-->
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.  [ 9 posts ] 
Author Message
 Post subject: PropertyValueException: not-null property references a null
PostPosted: Fri May 04, 2007 3:29 am 
Newbie

Joined: Fri May 04, 2007 3:10 am
Posts: 5
Hi all,

Am getting an exception as shown below, while trying to insert a new row of customer details in a table called CustClientData

PropertyValueException: not-null property references a null or transient value: com.lesconcierges.smartagent.datatransfer.CustClientData.customer

the mapping file i have used is:-

<hibernate-mapping>
<class
name="com.lesconcierges.smartagent.datatransfer.CustClientData"
table="CustClientData"
>

<id
name="customerId"
type="java.lang.Integer"
column="customerID">
<generator class="assigned"/>
</id>

<!-- associations -->
<!-- bi-directional one-to-one association to Customer -->
<one-to-one
name="customer"
class="com.lesconcierges.smartagent.datatransfer.Customer"
outer-join="auto"
constrained="true"
/>

</class>
</hibernate-mapping>

the code which does the insert is :-

Transaction tx1 = session.beginTransaction();
CustClientData custCliData = new CustClientData();
custCliData.setCustomerId(customer.getCustomerId()); // here i used an valid customer id which is present in the customer table
session.save(custCliData);
session.flush();
tx1.commit();

can anyone provide a solution for this..
Expecting a favourable reply
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 3:39 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
when you are saving custCliData, before that set custCliData.setCustomer(CustomerObject). This CustomerObject be selected from the db before you set or else it will create a new CustomerObject row in db.

-Vikash


Top
 Profile  
 
 Post subject: I have already done what you have said.. but still exception
PostPosted: Fri May 04, 2007 3:53 am 
Newbie

Joined: Fri May 04, 2007 3:10 am
Posts: 5
Hi vikas,

i have also set the customer object in custCliData instead of customerid using a set method called setCustomer(customerOBJ), and also the customer object is a valid one which i fetched from the db.

any other solution you could give please, i have searched many forums reg this...but all have posted some replies based on the mapping xml file, but i could not understand that clearly


Last edited by samy_se on Fri May 04, 2007 3:56 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: I have already done what you have said.. but still exception
PostPosted: Fri May 04, 2007 3:54 am 
Newbie

Joined: Fri May 04, 2007 3:10 am
Posts: 5
Hi vikas,

i have also set the customer object in custCliData instead of customerid using a set method called setCustomer(customerOBJ), and also the customer object is a valid one which i fetched from the db.

any other solution you could give please, i have searched many forums reg this...but all have posted some replies based on the mapping xml file, but i could not understand that clearly


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 4:19 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
can you check with this mapping ---->


<hibernate-mapping>
<class name="com.lesconcierges.smartagent.datatransfer.CustClientData" table="CustClientData">
<id name="custClientId" type="java.lang.Integer" column="custClientId">
<generator class="increment"/>
</id>

<many-to-one name="customer" column="customerID" cascade="all" class="com.lesconcierges.smartagent.datatransfer.Customer"/>
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="com.lesconcierges.smartagent.datatransfer.Customer" table="Customer">
<id name="customerID" type="java.lang.Integer" column="customerID">
<generator class="increment"/>
</id>

<many-to-one name="customer" column="customerID" cascade="all" class="com.lesconcierges.smartagent.datatransfer.Customer"/>
</class>
</hibernate-mapping>

Java code

Transaction tx1 = session.beginTransaction();
CustClientData custCliData = new CustClientData();
Customer customer = (Customer)session.createCriteria(Customer.class).add(Expr.eq(customerId, 1/2/3)).uniqueResult();
custCliData.setCustomer(customer); // here set the customer object for custCliData object which is present in the customer table
session.save(customer);
session.save(custCliData);
session.flush();
tx1.commit();


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 4:20 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
can you check with this mapping ---->


<hibernate-mapping>
<class name="com.lesconcierges.smartagent.datatransfer.CustClientData" table="CustClientData">
<id name="custClientId" type="java.lang.Integer" column="custClientId">
<generator class="increment"/>
</id>
.
.
.

<many-to-one name="customer" column="customerID" cascade="all" class="com.lesconcierges.smartagent.datatransfer.Customer"/>
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="com.lesconcierges.smartagent.datatransfer.Customer" table="Customer">
<id name="customerID" type="java.lang.Integer" column="customerID">
<generator class="increment"/>
</id>

<property />
.
.
.

</hibernate-mapping>

Java code

Transaction tx1 = session.beginTransaction();
CustClientData custCliData = new CustClientData();
Customer customer = (Customer)session.createCriteria(Customer.class).add(Expr.eq(customerId, 1/2/3)).uniqueResult();
custCliData.setCustomer(customer); // here set the customer object for custCliData object which is present in the customer table
session.save(customer);
session.save(custCliData);
session.flush();
tx1.commit();

Best of luck
Vikash


Top
 Profile  
 
 Post subject: one-to-one mapping
PostPosted: Fri May 04, 2007 5:27 am 
Newbie

Joined: Fri May 04, 2007 3:10 am
Posts: 5
hi vik,

it should be an one-to-one mapping...but you have mentioned many-to-one, and also did u mentioned any default value for customerID, that value is possible from db


Top
 Profile  
 
 Post subject: its solved bcoz of both setCustomer() and setCustomerID()
PostPosted: Fri May 04, 2007 6:07 am 
Newbie

Joined: Fri May 04, 2007 3:10 am
Posts: 5
Hi vik,

Finally i solved that issue by just using both set methods that i had setCustomer() and setCustomerID() to insert customer row.

Anyway thanks for your time and effort

Regards,
samy


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 6:17 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
Hi Sam,

the customerId is auto incremented by hibernate and will be identified as a unique key for customer a primary key.

-Vikash

_________________
get hibernate & get addicted


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