Missed Team ’24? Catch up on announcements here.

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

Active Objects - How to implement one-to-many and one-to-one?

codelab expert
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.
April 18, 2013

How to implement one-to-many and one-to-one (some code sample)? Is it possible to integrate referenced integrity (delete records when the master record is deleted or updated)?

Thank you!

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
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.
April 18, 2013

1. Relationships

Its done with annotations, here is a one-to-one excerpt from JEMH, in my ConfigEntity I have:

@OneToOne

public JEMHPGPConfigEntity getGPGConfiguration();

And likewise, a one-to-many:

@OneToMany
JEMHProjectMappingEntity[] getProjectMappings();
The trick is that the referred entities above all have a getter/setter pair for the owning ConfigEntity.
2. Cascade delete
No, not that I'm aware of. You have to do a bottom up delete.
Shaikh Moiz July 25, 2013

Hello Andy,

Can i know how can i insert data in the child table as,

say if i have a table as myTable and the other table as childTable,

now if i want to insert data into childTable how can i achieve that ,child table is one which is referering the primary key of the myTable., i am not able to get it ,can you please share a code snippet.

Thanks and regards,

--Moiz

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.
July 25, 2013

you have to add a setter on the child to take the type of the parent, eg

public void setParent(ParentType pt);

then the @OneToMany or @OneToOne will automatically resolve, so that (from the parent) then resolves:

@OneToMany

public ChildType[] getChildren();

Shaikh Moiz July 25, 2013

Thanks andy for your kind help,

but i got an error as,

org.postgresql.util.PSQLException: ERROR: relation "public.AO_CCE27F_XYZ_ID_seq" does not exist

am i missing something..

--Moiz

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.
July 25, 2013

possibly database permissions required for the connecting user in order to create those sequences. assuming all entities are (a) annotated as such and (b) referred in atlassian-plugin.xml

Shaikh Moiz July 25, 2013

yeah i was not able to create via plugin but when i manually created above specified table the error was resolved,

in my atlassian-plugin.xml do i need to add both entities as

<ao key="ao-module-main">
  		<description>The module configuring the Active Objects service used by this plugin</description>
 		 <entity>com.auto.actObj.MainObject</entity>
		  
	</ao>
	
<ao key="ao-Assigneemodule">
  		<description>The module configuring the Active Objects service used by this plugin</description>
 		 <entity>com.auto.actObj.XYZ</entity>
		  
	</ao>

but when i do so i got another error as,

com.atlassian.plugin.PluginException: com.atlassian.activeobjects.osgi.TooManyServicesFoundException: Was expecting one service reference for interface <com.atlassian.activeobjects.config.ActiveObjectsConfiguration> and filter <(com.atlassian.plugin.key=xyz.XYZ)>. Got 2 !

when i comment the second module i am able to recompile but not able to create both tables.

--Moiz

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.
July 25, 2013

You should only have one <ao></ao> with all entities therein. If you have further questions, please post a new question.

Shaikh Moiz July 28, 2013

Hi andy,

Thanks for your support.this really solved my problem.

--Moiz.

TAGS
AUG Leaders

Atlassian Community Events