-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Simple @OneToMany mapping question
PostPosted: Tue Jan 25, 2011 6:44 pm 
Beginner
Beginner

Joined: Mon Jan 04, 2010 2:52 pm
Posts: 30
hello,

I have projects which contain SequenceLists:
Code:
   @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
   @org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.ALL,
                                      org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
   private List<SequenceList> hitlists;

This is the place where SequenceLists are stored: When a project is saved,
all SequenceLists are saved along with it.

This works fine. However, now I added the Report-class which holds references
to SequenceLists:
Code:
   @OneToMany
   private List<SequenceList> sequencelists;

I do not cascade because these references are independent from the
Projects, where SequenceLists are stored: The Reports are like a shopping
bag: you add/remove SequenceLists (without affecting the persistence of the
objects in the project!) and then hit the "Create PDF" button.

However, with the above mapping, I cannot have two Reports which
contain the same SequenceList (which is perfectly legal according to my
understanding of @OneToMany and must be supported by the application).
Is the above mapping for "sequencelists" wrong?

On the SQL level, it seems there is a unique constraint not on the
combination of Report-id and SequenceList-id (the table for Report is oddly
named "reports2"), but on sequencelists_id(!):

select * from reports2_sequencelists;
=> yields (2,1)

insert into reports2_sequencelists (reports2_id, sequencelists_id) values (3, 1);
=> Violation of unique constraint SYS_CT_363: duplicate value(s) for column(s)
SEQUENCELISTS_ID / Error Code: -104 / State: 23000

I am running a HSQLDB-Database.

Thanks a lot in advance !!


Top
 Profile  
 
 Post subject: Re: Simple @OneToMany mapping question
PostPosted: Wed Jan 26, 2011 2:57 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
However, with the above mapping, I cannot have two Reports which
contain the same SequenceList (which is perfectly legal according to my
understanding of @OneToMany and must be supported by the application).
Is the above mapping for "sequencelists" wrong?


Yes, the mapping is incorrect. You should use @ManyToMany instead of @OneToMany.


Top
 Profile  
 
 Post subject: Re: Simple @OneToMany mapping question
PostPosted: Wed Jan 26, 2011 3:43 am 
Beginner
Beginner

Joined: Mon Jan 04, 2010 2:52 pm
Posts: 30
Thanks! Such a simple thing :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.