-->
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.  [ 1 post ] 
Author Message
 Post subject: Cascading association:not-null property references a null or
PostPosted: Wed Oct 20, 2010 4:40 am 
Newbie

Joined: Sat Dec 01, 2007 7:33 am
Posts: 8
bonjour,

j'ai deux entités book et publisher liées par une association type many-to-one. lorsque j'ai essayé de mettre à jour l'association une erreur hibernate se produit :

org.hibernate.PropertyValueException: not-null property references a null or transient value: tn.com.smartsoft.hibernate.beans.Book.publisher



les fichiers de mapping :

<!-- Publisher mapping -->
<hibernate-mapping>
<class name="tn.com.smartsoft.hibernate.beans.Publisher" table="publisher" catalog="bookshopdb">
<id name="publisherId" type="java.lang.Long">
<column name="PUBLISHER__ID" default="100" />
<generator class="increment" />
</id>
<property name="code" type="java.lang.String">
<column name="CODE" length="25" not-null="true" unique="true" />
</property>
<property name="publisherName" type="java.lang.String">
<column name="PUBLISHER_NAME" length="25" />
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" length="75" />
</property>

<set name="books" inverse="true" cascade="all">
<key>
<column name="PUBLICHER_ID" />
</key>
<one-to-many class="tn.com.smartsoft.hibernate.beans.Book" />
</set>


</class>
</hibernate-mapping>

<!-- Publisher mapping -->
<hibernate-mapping>
<class name="tn.com.smartsoft.hibernate.beans.Book" table="book" catalog="bookshopdb">
<id name="bookId" type="java.lang.Long">
<column name="BOOK_ID" />
<generator class="native" />
</id>
<property name="isbn" type="java.lang.String">
<column name="ISBN" length="20" not-null="true" unique="true" />
</property>
<property name="bookName" type="java.lang.String">
<column name="BOOK_NAME" length="225" />
</property>
<property name="publishDate" type="java.util.Date">
<column name="PUBLISH_DATE" length="10" />
</property>
<property name="price" type="java.lang.Long">
<column name="PRICE" precision="10" scale="0" />
</property>
<many-to-one name="publisher" class="tn.com.smartsoft.hibernate.beans.Publisher" lazy="proxy" cascade="save-update" fetch="join">
<column name="PUBLICHER_ID" not-null="true" />
</many-to-one>

<set name="chapters" inverse="true">
<key>
<column name="BOOK_ID" not-null="true" />
</key>
<one-to-many class="tn.com.smartsoft.hibernate.beans.Chapter" />
</set>
</class>
</hibernate-mapping>



j'ai créer un nouvel objet de type book et un autre de type publisher lorsque j'execute le code suivant :

Book book = new Book();
book.setBookName("My BOOK1");
book.setIsbn("123456");
book.setPrice(Long.valueOf(10));

Publisher publisher = new Publisher();
publisher.setCode("18");
publisher.setPublisherName("Publisher1");
book.setPublisher(publisher);

Session session = HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
session.saveOrUpdate(book);
tx.commit();
session.close();

l'erreure suivante se produit :

org.hibernate.PropertyValueException: not-null property references a null or transient value: tn.com.smartsoft.hibernate.beans.Book.publisher


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.