-->
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: @OneToMany Problem
PostPosted: Wed Aug 13, 2008 9:56 am 
Newbie

Joined: Wed Nov 07, 2007 3:58 pm
Posts: 15
Hi,

i have a little mapping problem...

Code:
@Entity
@Table
public class VersionDescriptor {

...

  @OneToMany(fetch = FetchType.LAZY)
  @Column(nullable=true)
  private List<VersionDescriptor> predecessors = new ArrayList<VersionDescriptor>();
   
...
   
  @OneToMany(cascade={CascadeType.ALL}, fetch = FetchType.LAZY)
  @Column(nullable=true)
  private List<VersionDescriptor> sucessors = new ArrayList<VersionDescriptor>();
   
...
}


is not mapped like exspected to the database. That means all (not listed attributes) are mapped to a VERSIONDESCRIPTOR table and for the predecessor and successor list a second table VERSIONDESCRIPTOR _VERSIONDESCRIPTOR is created that contains versiondescriptor_uid, predecessor_uid and successor_uid.
BUT the problem is that these columns are configured as NOT NULL instead of NULLABLE. What can i do to resolve this issue ? For example - I am getting errors if i try to insert only a successor, because Hibernate tells me that there is no defaultvalue for the other (predecessor)...


Removing this restriction directly on the DB works fine and i can produce something like this:
Code:
versiondescriptor_uid | predecessor_uid | successor_uid
4 | 5 | NULL
5 | NULL |4
5 | 6 | NULL
...


I already thought about telling Hibernate to create two seperate tables for it... but how? or is there a simpler solution ?

Cheers Tobias


Top
 Profile  
 
 Post subject: Solution
PostPosted: Wed Aug 13, 2008 11:37 am 
Newbie

Joined: Wed Nov 07, 2007 3:58 pm
Posts: 15
@JoinTable did the job :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 2:00 pm 
Beginner
Beginner

Joined: Fri Aug 05, 2005 3:36 am
Posts: 28
Well if it works, then that's good.

It seems like you might map things differently, though, with less records and less columns. As it is, you have two rows for each predecessor/successor relationship, right? And you always have one NULL in either the predecessor (P) or successor (S) column, right?

How about modeling it with one table, where each row represents a P/S relationship. The table has only two columns - P and S. The predecessors relationships of an object are represented by those rows where the object's ID appears in the P column. Its successor relationships are represented by the rows where it appears in the S column.

You'd have half the records, and one less column. Referential integrity would be easier to maintain, I'd figure.

You think?

-larry


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.