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
|
|