userbb
userbb

Reputation: 1874

Prevent 'not-null property references a null or transient value'

I have mapping

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DatabaseAccess" namespace="DatabaseAccess.poco">
  <class name="Employee" table="emplyees" lazy="true">
    <id name="id">
      <generator class="increment"></generator>
    </id>

    <property name="first_name" not-null="true"></property>
    <property name="last_name" not-null="true"></property>
    <property name="login" not-null="true"></property>
    <property name="sid"></property> 

  </class>
</hibernate-mapping>

What I can do if session.Save(object) do not throw exception: not-null property references a null or transient value I want to fill these nulls before commit anyway.

Upvotes: 1

Views: 6644

Answers (1)

gdoron
gdoron

Reputation: 150263

What I can do if session.Save(object) do not throw exception: not-null property references a null or transient value I want to fill these nulls before commit anyway.

  • Change the mapping to be not nullable.
  • fill those null before saving.
  • update the saved entity:

 session.Save(obj);
 obj.Foo = new foo();

//session.SaveOrUpdate(object) // required if it's a new session.

Upvotes: 1

Related Questions