-->
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: one-to-one lazy loading issue
PostPosted: Sun Jun 03, 2007 9:37 pm 
Newbie

Joined: Tue May 08, 2007 12:25 am
Posts: 18
I'm trying to persist an object with a many-to-one relationship since I want to use lazy loading. I have a foreign key on my "profile" class, that uses the primary key of my "user" class. I've read the following http://www.hibernate.org/162.html and I believe I'm doing this right

1. what is causing this "null id generated"
2. how is everybody solving this one-to-one lazy loading issue?

however, when I try to persist my object I get the following
Hibernate version:
3.0
Mapping documents:
Code:
<class name="com.familyoven.user.User" table="users">
        <id name="id" column="ID">
            <generator class="identity"/>   
        </id>
       <many-to-one column="id" cascade="all" name="profile" class="com.familyoven.user.Profile"
         unique="true" />
</class>

  <class name="com.familyoven.user.Profile" table="users_profiles">
        <id name="id" column="id">
         <generator class="foreign">
               <param name="property">user</param>
           </generator>
        </id>
      <one-to-one name="user" class="com.familyoven.user.User" constrained="true" />
</class>

Code between sessionFactory.openSession() and session.close():
Code:
User user = new User();
   user.setName('George Bush');

  Profile profile = new Profile();
  profile.setUser( user );
  user.setProfile( profile );
   session.save( user );

Full stack trace of any exception that occurs:
Code:
org.hibernate.id.IdentifierGenerationException: null id generated for:class com.familyoven.user.Profile
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:531)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
   at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
   at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
   at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:385)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:242)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
   at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:559)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:543)
   at sun.reflect.GeneratedMethodAccessor162.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
   at $Proxy0.save(Unknown Source)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 12:29 am 
Newbie

Joined: Thu Apr 21, 2005 6:04 am
Posts: 8
Download myeclipsse tool , they have 1 month trial.

1. Use that to generate code from tables.

2. Use increment for id auto generation.

3. follow my posts.
http://forum.hibernate.org/viewtopic.php?t=975613

I just did one to many , many to one with hibernate 3.1

Download hibernate 3.1 source (sourceforge) for debugging if you have problems.

When you download myeclipse ide , download full set (based on eclipse previous version) not the eclipse plugin.

goodluck.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 10:55 am 
Newbie

Joined: Tue May 08, 2007 12:25 am
Posts: 18
I appreciate hte response, however, I do not want to use increment for key generation. I'd like to use a foreign key. Using increment means i'd have to keep another index (one for the surragate key and one for the foreign key) on the table which is wasteful and time consuming


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.