-->
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: constructors with arguments but Hibernates uses no args
PostPosted: Thu Feb 16, 2006 2:17 pm 
Newbie

Joined: Wed Aug 31, 2005 9:13 am
Posts: 8
Location: Springfield, VA
Converting to Hibernate. My factory class is replaced by discriminator values from record to determine the subclass to instantiate. Hibernate forces the use of no argument constructor.

My factory class set up data/associations within the object before returning it. How do i set up data in objects on a load? Was it a bad design passing in associated data into the constructor?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 10:53 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You just need to add a second constructor, for Hibernate. The design isn't bad. You shouldn't need to set up any data for an object being loaded by Hibernate. When the object was originally created (before it was saved for the first time), your factory created the object using the parameterized constructor. Whatever values were set up at that time were saved to the DB. When you load the object later, those values are loaded with it.

If for some reason you need to set up values that are not saved to the DB, there are still plenty of options. You could use a PostLoadEventListener, redesign your entities or factories, use default values, etc...


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.