Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Active Object Table Not Creating

Shane Froebel December 8, 2013

I have everything done per the documentation. I think I read it at least 20 times over. My code is 98% working because everything compiles and run's under 'atlas-run'. I created a JUnit test to see if tables were being created, and beleive it or not, tables are not being created. I thought this was happening because I would check System --> Plugin Data Storage and never see the tables being listed.

Here are the relvent sections truncated.. of course.

pom.xml

        <dependency>
        	<groupId>com.atlassian.activeobjects</groupId>
        	<artifactId>activeobjects-plugin</artifactId>
        	<version>${ao.version}</version>
        	<scope>provided</scope>
        </dependency>
<dependency>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-test</artifactId>
<version>${ao.version}</version>
<scope>test</scope>
</dependency>

atlassian-plugin.xml

  <ao key="inventory-ao-module">
  	<entity>xx.ao.db.AoDevice</entity>
        <entity>xx.ao.db.AoDeviceEvent</entity>
  </ao>
<component key="inventory-service-device" class="xx.service.DeviceServiceImpl"
interface="xx.service.DeviceService" public="true" />

AoDevice.Java

package xx.ao.db;

import net.java.ao.Entity;
import net.java.ao.Mutator;
import net.java.ao.OneToMany;
import net.java.ao.Preload;
import net.java.ao.schema.Table;

import java.util.Date;

@Preload
@Table("Device")
public interface AoDevice extends Entity {

.. truncated ..

	//Host Name
	@Mutator(HOSTNAME_COLUMN)
	public String getHostname();
	public void setHostname(String hostname);

.. truncated ..

}

DeviceServiceImpl.Java

public final class DeviceServiceImpl implements DeviceService
{
	
	private final ActiveObjects activeObjects;

    public DeviceServiceImpl(ActiveObjects activeObjects)
    {
        this.activeObjects = activeObjects;
    }
	
    public AoDevice addDevice()
    {
    	AoDevice device = activeObjects.create(AoDevice.class);

So. If there is anyting else you need, let me know. Thanks in advance.

5 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 9, 2013

Yes it should work but using a proper database eg Postgresql so you can connect to the db externally to visualise what tables have been created. With hsql its a little tricky.

What can happen with AO is a table is created but is in an inconsistent state.

With hsql what you can do to 'clear' existing data is to remove all entities from the atlassian-plugin.xml : <ao key="inventory-ao-module">, then redeploy, this should drop all the hsql tables, reverting to entities included and deploy, you'll get a clear run of entitiy creation.

Turning on ao logging will also clue you in as to what is going on under the covers:

- net.java.ao

- net.java.ao.sql

Shane Froebel December 13, 2013

So I know see this during JUnit Testing:

Running ut.net.frakmedia.plugin.inventory.DeviceUnitTest
DEBUG -                                              net.java.ao.sql - CREATE T
BLE PUBLIC.AO_000000_DEVICE (
    ADDED DATETIME,
    DESC VARCHAR(255),
    DESCRIPTION VARCHAR(255),
    EXPIRE DATETIME,
    HOSTNAME VARCHAR(255),
    ID INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL,
    IP VARCHAR(255),
    LASTSCAN DATETIME,
    MACADDRESS VARCHAR(255),
    NEXTSCAN DATETIME,
    SERIAL VARCHAR(255),
    SERIALNUMBER VARCHAR(255),
    UPDATED DATETIME,
    PRIMARY KEY(ID)
)

Don't quite understand why it's set to 00000

Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2013

Given you're in a unit test its likely related to how you are initialising AO (or not).

Are you following:

- https://developer.atlassian.com/display/DOCS/Getting+Started+with+Active+Objects#GettingStartedwithActiveObjects-Step13.SeedtheDatabasewithsomeTestData?

0 votes
Hy Nguyen November 25, 2018

I got the same situation. The key is to add the migrating to the begining of your test function



@Test

public void testAoDevice() {

ao.migrate(AoDevice.class);

// You test code here
ao.createSomeThing();
...
}

0 votes
Shane Froebel December 8, 2013

@Matt Doar - Going to have to stay for the tutorial is what I read 20 times. And I have looked at the aO-tutorial too about that many times as well. Trust me. I know it throughly.

@John Bishop - Yes.

During the stack trace during a JUnit test I get this trace:

com.atlassian.activeobjects.internal.ActiveObjectsSqlException: There was a SQL exception thrown by the Active Objects library:
Database:
	- name:HSQL Database Engine
	- version:1.8.0
	- minor version:8
	- major version:1
Driver:
	- name:HSQL Database Engine Driver
	- version:1.8.0

java.sql.SQLException: Table not found in statement [INSERT INTO AO_000000_DEVICE (ID) VALUES (NULL)]
	at com.atlassian.activeobjects.internal.EntityManagedActiveObjects.create(EntityManagedActiveObjects.java:93)
	at net.frakmedia.plugin.inventory.service.DeviceServiceImpl.addDevice(DeviceServiceImpl.java:32)
	at ut.xx.DeviceUnitTest.createDeviceIpv4(DeviceUnitTest.java:57)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
	at net.java.ao.test.junit.ActiveObjectTransactionMethodRule$1.evaluate(ActiveObjectTransactionMethodRule.java:86)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLException: Table not found in statement [INSERT INTO AO_000000_DEVICE (ID) VALUES (NULL)]
	at org.hsqldb.jdbc.Util.throwError(Unknown Source)
	at org.hsqldb.jdbc.jdbcPreparedStatement.&lt;init&gt;(Unknown Source)
	at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
	at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
	at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.java.ao.DelegateConnectionHandler.delegate(DelegateConnectionHandler.java:94)
	at net.java.ao.DelegateConnectionHandler.invoke(DelegateConnectionHandler.java:62)
	at com.sun.proxy.$Proxy12.prepareStatement(Unknown Source)
	at net.java.ao.DatabaseProvider.preparedStatement(DatabaseProvider.java:2275)
	at net.java.ao.db.HSQLDatabaseProvider.executeInsertReturningKey(HSQLDatabaseProvider.java:111)
	at net.java.ao.db.HSQLDatabaseProvider.insertReturningKey(HSQLDatabaseProvider.java:101)
	at net.java.ao.EntityManager.create(EntityManager.java:460)
	at com.atlassian.activeobjects.internal.EntityManagedActiveObjects.create(EntityManagedActiveObjects.java:89)
	... 28 more

I am also seeing something related to 'mojo' but I have yet to read anything on it.

Pawel Duleba June 30, 2016

You have to call : 

activeObjects.migrate(AoDevice.class)

More can be found here : https://activeobjects.java.net/0.8.2/ActiveObjects.pdf 

0 votes
MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 8, 2013

Hard to debug from that and no log file. Personally I'd start with the tutorial

https://developer.atlassian.com/display/DOCS/Getting+Started+with+Active+Objects

and the source code at

https://bitbucket.org/atlassian_tutorial/ao-tutorial

and see if you can get that working, then see what's different with your code.


0 votes
John Bishop
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 8, 2013

1. Are you sure that the addDevice method of DeviceServiceImpl is being called?

2. Have you checked Jira's logs to see if Jira encountered and documented any errors?

3. Can you run the atlas-debug command and step through the code to make sure it is all running the way you want?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events