-->
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.  [ 3 posts ] 
Author Message
 Post subject: trouble persisting child object
PostPosted: Mon Jul 18, 2005 4:34 pm 
Newbie

Joined: Wed Feb 23, 2005 2:08 pm
Posts: 17
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
The parent object is persisted but I get an exception on the child object.

not-null property references a null or transient value

Any help would be greatly appreciated.

Scott



Hibernate version:2.14

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.model.Order" table="poc_orders">
<id name="orderId" type="long" column="orderid" unsaved-value="0" >
<generator class="sequence">
<param name="sequence">uid_sequence</param>
</generator>
</id>
<property name="batchId" column="batchId" not-null="true"/>
<property name="progSolNumber" column="prog_sol_number" not-null="true"/>

<set name="orderedProducts" table="POC_ORDERED_PRODUCTS" lazy="false" cascade="all" inverse="true">
<key column="ORDERID" />
<one-to-many class="com.model.OrderedProduct" />
</set>

</class>
</hibernate-mapping>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.model.OrderedProduct" table="poc_ordered_products">
<id name="id" type="long" column="recid" unsaved-value="0" >
<generator class="sequence">
<param name="sequence">uid_sequence</param>
</generator>
</id>
<many-to-one name="order" class="com.model.Order" column="orderid" not-null="true" />
<property name="productId" column="productId" not-null="true"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close(): I am using spring

Full stack trace of any exception that occurs:

Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@1e58cb8 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@1e57e8f [ acquireIncrement -> 3, autoCommitOnClose -> false, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> -1, initialPoolSize -> 3, maxIdleTime -> 0, maxPoolSize -> 15, maxStatements -> 0, minPoolSize -> 3, nestedDataSource -> propertyCycle -> 300, testConnectionOnCheckout -> false ] , factoryClassLocation -> null, numHelperThreads -> 3 ]
- Use scrollable result sets: true
- Use JDBC3 getGeneratedKeys(): false
- Optimize cache for minimal puts: false
- Query language substitutions: {}
- cache provider: net.sf.ehcache.hibernate.Provider
- instantiating and configuring caches
- building session factory
- no JNDI name configured
- Creating shared instance of singleton bean 'transactionManager'
- Using DataSource [com.mchange.v2.c3p0.ComboPooledDataSource@e183e9] from Hibernate SessionFactory for HibernateTransactionManager
- Creating shared instance of singleton bean 'productDAO'
- Creating shared instance of singleton bean 'workingDAO'
- Creating shared instance of singleton bean 'outcomeLogDAO'
- Creating shared instance of singleton bean 'outcomeProductDAO'
- Creating shared instance of singleton bean 'orderedProductDAO'
- Creating shared instance of singleton bean 'orderDAO'
- Creating shared instance of singleton bean 'productManager'
- Creating shared instance of singleton bean 'productManagerTarget'
- Creating shared instance of singleton bean 'outcomeLogManager'
- Creating shared instance of singleton bean 'outcomeLogManagerTarget'
- Creating shared instance of singleton bean 'decisionManager'
.E
Time: 0.911
There was 1 error:
1) testAdd(com.dao.OrderDAOTest)org.springframework.orm.hibernate.HibernateSystemException: not-null property references a null or transient value: com.model.OrderedProduct.order; nested exception is net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: com.model.OrderedProduct.order
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: com.model.OrderedProduct.order


Name and version of the database you are using:Oracle 9i

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

public class Order extends BaseObject{
private String progSolNumber;
private long orderId;
private long batchId;
private Set orderedProducts;
public String getProgSolNumber() {
return progSolNumber;
}

public void setProgSolNumber(String progSolNumber) {
this.progSolNumber = progSolNumber;
}

public long getOrderId() {
return orderId;
}

protected void setOrderId(long orderId) {
this.orderId = orderId;
}

public long getBatchId() {
return batchId;
}

public void setBatchId(long batchId) {
this.batchId = batchId;
}
public Set getOrderedProducts() {
return orderedProducts;
}

public void setOrderedProducts(Set orderedProducts) {
this.orderedProducts = orderedProducts;
}


public class OrderedProduct extends BaseObject{
private long id;

private long orderId;
private long productId;
private Order order;

public long getId() {
return id;
}

protected void setId(long id) {
this.id = id;
}


public long getOrderId() {
return order.getOrderId();
}

public Order getOrder() {
return order;
}

public void setOrder(Order order) {
this.order = order;
}

public long getproductId() {
return productId;
}

public void setProductId(long productId) {
this.productId = productId;
}


}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 8:57 am 
Newbie

Joined: Tue Mar 08, 2005 4:54 pm
Posts: 9
Location: GHANA WEST-AFRICA
if you have no answers still i think i can help. i solved this long ago.please let me know at @ pkkamos@yahoo.com. glad to help you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 9:06 am 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
First of all: your unsaved value is "0", this could be a problem when trying to save multiple instances default initialized with 0 (PK should be unique).
Second: check you database on null values on the id and not null fields. This should not be possible!

_________________
Dencel
- The sun has never seen a shadow -


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