-->
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: Default Value - Exclude from INSERT
PostPosted: Sat Nov 21, 2009 3:33 pm 
Newbie

Joined: Wed Jul 14, 2004 8:09 pm
Posts: 6
Location: Sofia, Bulgaria
I am a pretty much a new user of Hibernate (though I have used it but this was long time ago). Now I get to use it again.

This is probably an easy (newbie) question.

I have MS SQL 2005 as RDBMS. I have in one table a column called LastModifiedDate of type datetime.
It is non-null column and it has 'Default value or binding' set to getdate()
/which is a function to get the current datetime in MS SQL 2005/.

In my mapped java class I want to force Hibernate to exclude this column when Hibernate generates INSERT SQL statements.
Why? Because the default value for a Date property in Java is null and I think Hibernate uses NULL in the generated SQL.
And because my column is non-null at DB level I get ConstraintViolationException.

How can I do that? How should I mark my java field/property/?

Currently it is marked this way.

@Column(name="LastModifiedDate")
private Date lastModifiedDate;

I guess there is a way to force Hibernate to just not use this field when generating INSERT SQL statements.

Thanks a lot in advance.

_________________
Peter Petrov


Top
 Profile  
 
 Post subject: Re: Default Value - Exclude from INSERT
PostPosted: Sat Nov 21, 2009 4:19 pm 
Newbie

Joined: Wed Jul 14, 2004 8:09 pm
Posts: 6
Location: Sofia, Bulgaria
I found my answer after reading this.
http://listarchive.cinjug.org/html/user ... 00024.html

The correct way to mark my java field/property/ is the following.

@Column(name="LastModifiedDate", nullable=false, insertable=false)
private Date lastModifiedDate;

Thanks anyway.

_________________
Peter Petrov


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.