-->
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: Limitations of <one-to-one> mapping
PostPosted: Thu Sep 04, 2003 6:41 am 
Newbie

Joined: Wed Aug 27, 2003 1:37 am
Posts: 10
Location: Kyrgyzstan
Hello,

I have a class that I want to be in a one-to-one object with multiple different objects. Unfortunately if I understand the hibernate <one-to-one> mapping correctly it works by selecting objects where the identifiers of each object are equal. In my case I need to create a one-to-one relationship where the foriegn key is not the same as the identifier.

Second problem:

When testing the foriegn generator I came across the following stack trace.
Code:
Exception in thread "main" net.sf.hibernate.AssertionFailure: null id
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:664)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1214)
   at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:81)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:238)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:306)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:708)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1214)
   at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:81)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:238)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:272)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:306)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:754)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1214)
   at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:81)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:238)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:272)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:306)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:754)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1214)
   at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:81)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:238)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:306)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:708)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1214)
   at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:81)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:238)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:306)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:708)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1214)
   at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:81)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:238)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:306)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:708)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620)
   at com.atwoodsoft.tests.client.DomainModelTest.saveStructure(DomainModelTest.java:504)
   at com.atwoodsoft.tests.client.DomainModelTest.main(DomainModelTest.java:708)


I suspect that what is happening is that the foreign generator does not work when the other object participating in the <one-to-one> relationship uses the native generator.

For now I suppose I will have to work around these problems by using <many-to-one> mappings instead of <one-to-one> mappings. Unfortunately this is less than optimal because my design really calls for <one-to-one> relationships.

As always any advice would be appreciated.

John Atwood


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 6:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate 2.1 supports one-to-one associations where ids are not equal. You use the property-ref attribute.


Top
 Profile  
 
 Post subject: Thanks!
PostPosted: Thu Sep 04, 2003 7:05 am 
Newbie

Joined: Wed Aug 27, 2003 1:37 am
Posts: 10
Location: Kyrgyzstan
Gavin,

Thanks for the swift reply. Your on the mark advice has gotten me out of more than one tight spot.

Thanks,
John Atwood


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.