-->
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.  [ 8 posts ] 
Author Message
 Post subject: Initialize the Child object ?
PostPosted: Thu Apr 15, 2010 7:53 am 
Newbie

Joined: Thu Nov 12, 2009 4:32 pm
Posts: 16
I have a one-to-many mappings and i am trying to initialize an attribute of my child object with some default value, but it appears that its not setting, any clue ?


Top
 Profile  
 
 Post subject: Re: Initialize the Child object ?
PostPosted: Thu Apr 15, 2010 8:00 am 
Beginner
Beginner

Joined: Sat Oct 18, 2008 10:25 am
Posts: 30
Can you post some source code?


Top
 Profile  
 
 Post subject: Re: Initialize the Child object ?
PostPosted: Thu Apr 15, 2010 8:29 am 
Newbie

Joined: Thu Nov 12, 2009 4:32 pm
Posts: 16
public class ClassA {
private String id1;
private String status;
private Set<ClassB> relationship = new HashSet<ClassB>();
public ClassA(){
this.status = 'E';
}
}

public class ClassB{
private String status;
private String id1;
public ClassB(){
this.status = 'A';
}
}

<hibernate-mapping package="com.xxx.xxx.test">
<class name="ClassA" table="table_class">
<id name="id1" column="id1" />
<property name="status" column="status"></property>
<set name="relationship" lazy="false" inverse="true">
<key column="id1"></key>
<one-to-many class="ClassB"/>
</set>
</class>
</hibernate-mapping>

the above are the 2 objects and the mapping class of parent object, let me know if you need any other code,


Top
 Profile  
 
 Post subject: Re: Initialize the Child object ?
PostPosted: Thu Apr 15, 2010 10:39 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
As long as the object is transient and not a detached or persisted object the initial value will work. Hibernate will use the setter and set the column value retrieved from DB.Hope this helps.
Please do not forget to rate


Top
 Profile  
 
 Post subject: Re: Initialize the Child object ?
PostPosted: Thu Apr 15, 2010 10:57 am 
Newbie

Joined: Thu Nov 12, 2009 4:32 pm
Posts: 16
can you send me some code samples on these,


Top
 Profile  
 
 Post subject: Re: Initialize the Child object ?
PostPosted: Thu Apr 15, 2010 11:19 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
If you are about to save an object which you have created from scratch on calling saveOrUpdate hibernate will save the status column with the default value that you have set.Try this first . hope this helps.
Please dont forget to rate


Top
 Profile  
 
 Post subject: Re: Initialize the Child object ?
PostPosted: Thu Apr 15, 2010 11:28 am 
Newbie

Joined: Thu Nov 12, 2009 4:32 pm
Posts: 16
i forgot to mention that i am trying to fetch the objects not saving/update


Top
 Profile  
 
 Post subject: Re: Initialize the Child object ?
PostPosted: Wed Apr 21, 2010 5:02 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
I am bit confused now. if you are trying to fetch then hibernate will use setters to set the properties. if you specify the peoperty as transient then you will not be able to save. If you provide me with a usecase I may be able to look into it further.Send me the actual code not pseudo code.


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