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
|