-->
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.  [ 4 posts ] 
Author Message
 Post subject: Versioning question
PostPosted: Tue Feb 22, 2005 5:49 pm 
Beginner
Beginner

Joined: Tue Dec 21, 2004 11:53 am
Posts: 42
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.7

Hi there. When I have an pojo with a version attribute. And this pojo is used by another pojo in a many-to-one association. Do I need to load the entire object before associating it with the parent object?

For eg.

Car has an Engine

When creating a new car with the following code:
Code:
Car car = new Car();
Engine engine = new Engine();
engine.setID(new Long(1));
car.setEngine(engine);

Hibernate tries to persist the engine pojo, even this engine (ID=1) exists on the table. Now if I have:
Code:
Car car = new Car();
Engine engine = (Engine)engineDAO.findByPrimaryKey(new Long(1));
car.setEngine(engine);


Works just fine. Must hibernate fetch the entire object when using versioning? Is there a workaround?

I'm using a timeStamp as versioning

Thanks all


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 6:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If the child is lazy class loadable then you can use session.load to generate a proxy (without hitting the database) and associate it with the parent.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 7:28 pm 
Newbie

Joined: Mon Feb 07, 2005 7:57 pm
Posts: 9
david wrote:
If the child is lazy class loadable then you can use session.load to generate a proxy (without hitting the database) and associate it with the parent.

Else, there's no other way right???


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 7:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Don't forget you can use the various cache levels to reduce database hits for objects. Alternatively, you could use native SQL or JDBC but, in this case, why use an ORM.


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