-->
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.  [ 5 posts ] 
Author Message
 Post subject: Default value in a column
PostPosted: Tue Jan 27, 2004 8:30 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:25 am
Posts: 45
Hi all!!!
I'm a beginner with hibernate, and I have a little problem, so I was wondering if anyone could help me...
The problem is that I need to asign a default value of 0 to a property, but I don't know how. I know that I can assign it to an <id> by using the unsaved-value poperty... but how can I make solve this with a property or column?

My mapping is somtthing like this:

<class name="Language">
<id name="code" type="long" column="code" unsaved-value="null">
<generator class="native"/>
</id>
<property name="ord" type="long"/>
<property name="name" type="string" length="40"/>
<property name="ident" type="string" length="40"/>
<property name="isoName" type="string" length="20"/>
</class>


ANd what I need is to have a dafault value of 0 in property "ord"...

Can anyone help me please?

Thanks in advance for any response!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 8:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Just assign it to your class property in the constructor of your class. Note that hibernate will overwrite it with the data read from the DB if you load an object. On save, hibernate will store the data currently contained in your object, eg. the default value you set in your constructor.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 8:46 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:25 am
Posts: 45
Thank you, but I don't really understand what you mean.
Can you show me an example?

Sorry for the inconvenience!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 8:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
public class Language {
private long ord = 0;
get/set
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 9:38 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:25 am
Posts: 45
Ok!!!
Thank you very much!!!


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