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.  [ 2 posts ] 
Author Message
 Post subject: Help with a Unidirectional OneToOne Mapping
PostPosted: Tue Apr 04, 2006 11:57 am 
Newbie

Joined: Tue Dec 28, 2004 7:41 pm
Posts: 7
Hibernate version:
3.1rc2
3.1beta6 annotations

Name and version of the database you are using:
MySql 4



I have the following relationship

Code:
GenericProfile (embedebble superclass)
-----------
profile_id
image (no image_id foreign key in this table)
...
..

that has a one-to-one unidirectional relationship to an image


Code:
Image
-----------
image_id
imageData
(profile_id) -- only in the database table not on the class
...
..



I have other sub classes of the GenericProfile that need to inherit the relationship. I can't make the relationship bi directional because GenericProfile is not an entity. I've tried many variations of the OneToOne annotation on the GenericProfile with no luck. E.g.

Code:
@OneToOne()   
@JoinColumn(name = "profile_id", referencedColumnName = "profile_id", nullable = false)


I've also searched the forum and saw that it might be possible with a ManyToOne or ManyToMany with the unique attribute set. E.g.

Code:
@ManyToMany()   
@JoinColumn(name = "profile_id", referencedColumnName = "profile_id", nullable = false, unique = true, insertable = false, updatable = false)


I've seen some posts that seem to indicate that it's impossible and others that say it is possible. Could anyone let me know if this is possible or not and possibly provide some advice on how I might be able to get around it if it is possible?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 5:27 pm 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
If I understand you correctly, the generic profile table has no reference to the image table, but the image table does to profile. This is a basic and highly used relationship type and Hibernate 3 doesn't support it. H3 only does one-to-one unidirectional from a table to another, so Generic profile would have to have the foreign key id of image. Basically, the including table (or object) has to have the reference, not the other way around. It is most annoying and all the work-arounds are messy.

In my opinion, this is the biggest strike against Hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.