-->
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.  [ 4 posts ] 
Author Message
 Post subject: default value problem for sql server
PostPosted: Sat Sep 29, 2007 1:05 am 
Beginner
Beginner

Joined: Sat May 12, 2007 2:55 am
Posts: 24
Hi friends,
i am using hibernate 3.0 and having a simple table in sqlserver2000,
Table structure - TestMe
id int PK,
name char(50) null,
pin int default '12345' not null

Mapping is like:
<hibernate-mapping>
<class name="com.Testme" table="testme">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="name" length="50" />
</property>
<property name="pin" type="java.lang.Integer">
<column name="pin" not-null="true"/>
</property>
</class>
</hibernate-mapping>

The code that stores data in TestMe table:
.....
Session session=HibernateSessionFactory.getSession();
Transaction tx=session.beginTransaction();
Testme obj=new Testme();
obj.setId(1);
obj.setName("nirav");
session.save(obj);
tx.commit();
.....

the pin column is set to default , so if not given data explicitly it should store 12345. but this code ends up with the exception like

Exception in insertorg.hibernate.PropertyValueException: not-null property references a null or transient value: com.Testme.pin

where as the expected behaviour is TestMe should have a record like
1 nirav 12345


thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 29, 2007 8:19 am 
Beginner
Beginner

Joined: Wed Feb 14, 2007 10:43 am
Posts: 21
If you have set default value in DB side, why do you even need to set not-null property for the column in mapping. It's simply not required. Change it to: <column name="pin"/>

Don't forget to rate :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 4:09 am 
Beginner
Beginner

Joined: Sat May 12, 2007 2:55 am
Posts: 24
did tried, but no success, still not inserting value in pin field.


Top
 Profile  
 
 Post subject: Re: default value problem for sql server
PostPosted: Mon Oct 01, 2007 9:09 am 
Newbie

Joined: Mon Oct 01, 2007 8:59 am
Posts: 18
use generated="never|insert|always" according to your requirement in the property tag
<property name="pin" column="pin" generated="insert"/>
[/code]


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