Results 1 to 3 of 3

Thread: net.sf.hibernate.PropertyValueException: not-null property

  1. #1
    Join Date
    Oct 2004
    Posts
    15

    Default net.sf.hibernate.PropertyValueException: not-null property

    I am having a typical problem here
    I have a Class A{a1, a2} and Class B{b1,a1,b2}
    relation is one to many where one A and multiple B
    A has an identity column "a1" which is used in B "a1" as foreign key.

    Now if I insert a record in A it gives error for the B object's foreign key "a1" saying that it is
    not-null property references a null or transient value
    net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: B.a1

    There is one way of doing this, if I put a dummy value in B.a1 then it works, and then once i get the identity column value from A.a1 I can put that value into B.a1. But this is not a good approach. Will highly appreciate if you have a good solution for this.

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    This is a Hibernate issue and has nothing to do with Spring. Could you show your classes mapping and sample code for instances creation?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Oct 2004
    Posts
    15

    Default

    I am getting this error

    nested exception is net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: com.paymentvoucher.dataaccess.bean.VoucherPymntAud DataBean.voucherId

    I have 2 databeans with 1 to many relation

    VoucherHdrTempDataBean - voucherId(Primary key Identity)
    PaymentAdvcTempDataBean - voucherId(Foreign key)

    Now when I try to save the VoucherHdrTempDataBean the above error occurs, since voucherId is not known till that time

    I am attaching the mapping file after removing unnecessary stuff from it.
    <hibernate-mapping package="com.paymentvoucher.dataaccess.bean">
    <class name="VoucherHdrTempDataBean" table="VO_VOUCH_HDR_TEMP">
    <id name="voucherId" type="java.lang.Integer" column="VOUCHER_ID" unsaved-value="null">
    <generator class="identity"/>
    </id>
    <set name="voucherPymntAudDataBeans" lazy="true" inverse="true" cascade="all" >
    <key>
    <column name="VOUCHER_ID" />
    </key>
    <one-to-many class="com.paymentvoucher.dataaccess.bean.VoucherP ymntAudDataBean"/>
    </set>
    </class>
    </hibernate-mapping>

    <hibernate-mapping package="com.paymentvoucher.dataaccess.bean">
    <class name="PaymentAdvcTempDataBean" table="VO_PYMNT_ADVC_TEMP">
    <id name="adviceId" type="java.lang.Integer" column="ADVICE_ID" unsaved-value="null">
    <generator class="identity"/>
    </id>
    <many-to-one name="voucherHdrTempDataBean" class="com.paymentvoucher.dataaccess.bean.VoucherH drTempDataBean"
    not-null="true" insert="false" update="false">
    <column name="VOUCHER_ID" />
    </many-to-one>
    </class>
    </hibernate-mapping>


    I did filled both the beans with values. Then I am trying to save the master bean,
    and fetching the identity value from master bean and filling it into detail bean and
    saving the detail bean.

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Replies: 2
    Last Post: Oct 17th, 2005, 08:41 PM
  3. Replies: 4
    Last Post: Sep 27th, 2005, 11:31 PM
  4. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  5. Strange Data Access Error
    By webifyit in forum Data
    Replies: 2
    Last Post: Dec 28th, 2004, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •