-->
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: Error: could not initialize collection
PostPosted: Mon Feb 02, 2004 1:58 am 
Newbie

Joined: Tue Jan 06, 2004 12:57 am
Posts: 14
After adding a one to many relationship in the mapping file (from StoreMaster to child PurchaseOrder) I get the following error:

net.sf.hibernate.JDBCException: could not initialize collection: [StoreMaster.purchaseOrders#132680-C]

This is the xml:

<class name="StoreMaster" table="store_master">
<id name="stockNumber" column="stock_number" type="string" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="description" column="description"/>
<set name="purchaseOrders" cascade="all" inverse="true">
<key column="stock_number"/>
<one-to-many class="PurchaseOrder"/>
</set>
</class>


<class name="PurchaseOrder" table="purchase_order">
<id name="uniqueKey" column="unique_key" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="orderNumber" column="order_number"/>
<property name="lineNumber" column="line_number"/>
<property name="subLine" column="sub_line"/>
<property name="stockNumber" column="stock_number"/>
</class>

Anyone know what it could be ?

Jeff.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 6:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1. stock_number must be a FK column in purchase_order where Hibernate will set the stockNumber id. Check that your data does not fail this FK link, or better add a constraint in your DB
2. inverse="true" means the link is managed by the other side. But you did not set a many-to-one on the other side. The link won't ever be managed. Read http://www.hibernate.org/Documentation/InsideExplanationOfInverseTrue
3. If the previous fails, show the code generation this exception and the full stacktrace.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Error: could not initialize collection
PostPosted: Mon Feb 02, 2004 7:13 pm 
Newbie

Joined: Tue Jan 06, 2004 12:57 am
Posts: 14
I have other one to many mappings working ok, but this one still fails. There is no null values in the foreign key column (of the child table).
I made sure that the table column names and types are correct in the javabean and xml mapping file.

I don't know where to find the code generation, but the stack trace shows:


junit.framework.AssertionFailedError: net.sf.hibernate.JDBCException: could not initialize collection: [StoreMaster.purchaseOrders#132680-C]
at junit.framework.Assert.fail(Assert.java:47)
at DBServiceTest.testGetStoreMaster(DBServiceTest.java:186)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)


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.