-->
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.  [ 6 posts ] 
Author Message
 Post subject: Any workaround to avoid the "getEntity" problem ?
PostPosted: Mon Dec 15, 2003 10:33 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 11:36 am
Posts: 46
Location: Rennes, France
Hi all,

I would like to avoid loading dependent objects to save persistent objects...and i am looking for a safe procedure (without any side_effects) to do that.

Here is my new problem, still around the sessionImpl.getEntity private method.

Here is my case:

Model:
Object A <---n--------1---->Object B

Use case:
I want to save a new Object A with the corresponding object B, then displaying the list of Object A (with the title of object B), as follow:

ObjectA.id | ObjectA.name | ObjectA.ObjectB.title


Procedure:
- I create a new Object A (new)
- I create an Object B (existing in the database) with the new method
- I do objectA.setObjectB(myObjectBWithOnlyId)
- I save objectA - This runs perfectly in my case.
- I load all objectA to display the list - ths works except I don't get the ObjectB title, because the used object is the one I set during the setObjectId method...without title.

Question : Have I to load the objectB instance from Hibernate (quite heavy object) ? Are there any parameter to avoid "old" objects ?

Are there other workarounds (except doing a redirect between the save and the displayList methods) ???

Please help.
Yann


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 4:43 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 11:36 am
Posts: 46
Location: Rennes, France
anybody for a little help ?


Top
 Profile  
 
 Post subject: Turkey-hunt ???
PostPosted: Fri Dec 19, 2003 10:29 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 11:36 am
Posts: 46
Location: Rennes, France
Hey, everyone has gone to turkey-hunt ? ;-)


Top
 Profile  
 
 Post subject: Re: Any workaround to avoid the "getEntity" proble
PostPosted: Fri Dec 19, 2003 1:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
yannraoul wrote:
Question : Have I to load the objectB instance from Hibernate (quite heavy object) ?

What about
Code:
select a.id, a.name, a.b.title from ObjectA a

yannraoul wrote:
Are there any parameter to avoid "old" objects ?

Can't follow you, what do you mean by old object

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 1:51 pm 
Beginner
Beginner

Joined: Tue Oct 07, 2003 11:36 am
Posts: 46
Location: Rennes, France
The "old" object is the one used in the following code from Hibernate source 2.0.3.

I mean it is an "already-existing-object-in-the-hibernate-local-repository (not cache)".



Code:
private Serializable doSave(Object object, Serializable id) throws HibernateException {
      
      ClassPersister persister = getPersister(object);
      
      Key key = null;
      final boolean identityCol;
      if (id==null) {
         if ( persister.isIdentifierAssignedByInsert() ) {
            identityCol=true;
         }
         else {
            throw new AssertionFailure("null id");
         }
      }
      else {
         identityCol=false;
      }
      
      if ( log.isTraceEnabled() ) log.trace( "saving " + MessageHelper.infoString(persister, id) );
      
      if (!identityCol) {   // if the id is generated by the database, we assign the key later
         key = new Key(id, persister);
         
         Object old = getEntity(key);
         if (old!= null) {
            if ( getEntry(old).status==DELETED ) {
               flush();
            }
            else {
               throw new HibernateException(
                  "The generated identifier is already in use: " +
                  MessageHelper.infoString(persister, id)
               );
            }
         }
         
         persister.setIdentifier(object, id);
      }
      


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 1:56 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
evict it first

_________________
Emmanuel


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