-->
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: how insert the default value for a property
PostPosted: Fri Sep 16, 2005 11:38 am 
Newbie

Joined: Thu Sep 01, 2005 10:35 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0

Name and version of the database you are using:SQL server




<hibernate-mapping package="com.onebeacon.diarytracking.ormapping.domain">
<class name="FeeCompany" table="FeeCompany">
<id name="FeeCompanyAbbr" type="java.lang.String" unsaved-value="null">
<column name="FeeCompanyAbbr" sql-type="java.lang.String" not-null="true" />
</id>
<property name="FeeCompanyName" column="FeeCompanyName" type="java.lang.String" length="40" lazy="true" />

</class>

</hibernate-mapping>


when i insert one record into FeeCompany and not provide the FeeCompanyName then hibernate insert the null by default becuz it's nullable colunm.

My question is how to force hibernate to insert the defualt value instead of null for that property.


please help me.............


Top
 Profile  
 
 Post subject: init field
PostPosted: Fri Sep 16, 2005 12:34 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
simply set the default in the field of your class, i.e.
class FeeCompany{
private String FeeCompanyName = "My Default Value";
}

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 1:10 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
If you do not want the default values in the POJO to cause problems in you business services, another option is using Interceptors.. You can set the default values, say, in the
Code:
public boolean onSave(...)

method.

Hope this is helpful.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 7:51 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
http://hibernate.org/118.html#A16


Top
 Profile  
 
 Post subject: what about timestamps?
PostPosted: Sat Sep 17, 2005 11:40 am 
Newbie

Joined: Sat Jan 29, 2005 7:09 am
Posts: 11
Hi - I was wondering how to do this for timestamp fields?

When I insert/update a row in a table, I want a timestamp field to be updated with the current database timestamp i.e. effectively something like:

insert into mytable (id,thetime) values (1,NOW())

and

update mytable set thetime = NOW() where id = 1

I do not want to use the Interceptor to simply set the value of 'new Date()' to my POJO, because the time would be wrong.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 17, 2005 10:23 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
use database triggers, if sql server support triggers


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.