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.  [ 3 posts ] 
Author Message
 Post subject: How to use database generated default value?
PostPosted: Wed Mar 07, 2007 11:38 am 
Beginner
Beginner

Joined: Thu Oct 26, 2006 4:45 am
Posts: 39
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.0.4

Mapping documents:

Code:
<class name="MyAssembly.Relation, MyAssembly" table="Relation">
  <id name="Id" type="Int32" column="RelationId">
     <generator class="identity"/>
  </id>

  <property name="CreatedOn" column="CreatedOn" type="DateTime"/>

  <joined-subclass name="MyAssembly.Person,MyAssembly" table="Person">
  <key column="RelationId"/>
  <property name="DateOfBirth" column="DateOfBirth" type="DateTime"/>
  <property name="FirstName" column="FirstName" type="String"/>
  " />

...



When storing a new Person, NHibernate creates a new (parent)record Relation.

In the database, we want CreatedOn to be database-generated datetimevalue.

However, NHibernate needs to add the Relationrecord first and than tries to store a NULL value for the CreatedOn property.

Is it possible to let NHibernate ignore the CreatedOn property when saving a new class to the database? If yes, how? If no, how to use database-generated default-values with NHibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 07, 2007 7:06 pm 
Beginner
Beginner

Joined: Tue Aug 30, 2005 2:33 am
Posts: 22
say this is your table

create table test (
id number(1) pRIMARY KEY,
ins date DEFAULT SYSDATE);

you could leave ins out of the mapping altogether.

or if you still want it for select, in the property

specify insert="false"
that way it will use the DB generated default value when the row is inserted.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 08, 2007 5:52 am 
Beginner
Beginner

Joined: Thu Oct 26, 2006 4:45 am
Posts: 39
sk08 wrote:
say this is your table

or if you still want it for select, in the property

specify insert="false"
that way it will use the DB generated default value when the row is inserted.


Thank you! insert="false" was what I needed.


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