Please help,
I'm using Hibernate version 2.1.6. I have two objects with parent/child relationship. When I tried to retrieve the child object data, I would get an error: "Failed to lazily initialze a collection". The child object have a composite id, could that be the reason it failed. Someone please help!!!
Mapping Doc:
Code:
[b][Parent Mapping][/b]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.fujimed.pdq.orm.HshipTo"
table="HShipTo"
>
<composite-id name="comp_id" class="com.fujimed.pdq.orm.HshipToPK">
<key-property
name="quoteNum"
column="QuoteNum"
type="java.lang.String"
length="20"
/>
<key-property
name="idx"
column="Idx"
type="java.lang.Integer"
length="10"
/>
</composite-id>
<property
name="stname"
type="java.lang.String"
column="STName"
length="75"
>
<meta attribute="scope-field">public</meta>
</property>
<property
name="stcstSfx"
type="java.lang.String"
column="STCstSfx"
length="6"
>
<meta attribute="scope-field">public</meta>
</property>
<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->
<!-- bi-directional one-to-one association to HshipTo2 -->
<one-to-one
name="hshipTo2"
class="com.fujimed.pdq.orm.HshipTo2"
outer-join="auto"
property-ref="hshipTo"
/>
<!-- bi-directional one-to-many association to Hrpgmstr -->
<set
name="hrpgmstrs"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="QuoteNum" />
<column name="STIdx" />
</key>
<one-to-many
class="com.fujimed.pdq.orm.Hrpgmstr"
/>
</set>
</class>
</hibernate-mapping>
[b][CHILD Mapping][/b]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.fujimed.pdq.orm.Hrpgmstr"
table="HRPGMstr"
>
<composite-id name="comp_id" class="com.fujimed.pdq.orm.HrpgmstrPK">
<key-property
name="quoteNum"
column="QuoteNum"
type="java.lang.String"
length="20"
/>
<key-property
name="lnk1"
column="LNK1"
type="java.lang.Integer"
length="10"
/>
</composite-id>
<property
name="dept"
type="java.lang.String"
column="Dept"
length="80"
>
<meta attribute="scope-field">public</meta>
</property>
<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->
<!-- bi-directional many-to-one association to HshipTo -->
<many-to-one
name="hshipTo"
class="com.fujimed.pdq.orm.HshipTo"
insert="false" update="false" not-null="true"
>
<column name="QuoteNum" />
<column name="STIdx" />
</many-to-one>
<!-- bi-directional one-to-one association to Hrmaster -->
<one-to-one
name="hrmaster"
class="com.fujimed.pdq.orm.Hrmaster"
outer-join="auto"
/>
</class>
</hibernate-mapping>
Code:Code:
hibernateSession = AppSession.getSession();
myTransaction = hibernateSession.beginTransaction();
HshipToPK pk = new HshipToPK("0012001200300104-1", new Integer(1));
HshipTo s = (HshipTo)hibernateSession.load(HshipTo.class,pk);
Set myset = (Set) s.getHrpgmstrs();
Iterator myiter = myset.iterator();
while (myiter.hasNext())
{
Hrpgmstr part = (Hrpgmstr) myiter.next();
out.print("Parts: " + part.getProdGrp());
}
myTransaction.commit();
hibernateSession.close();
Stack Trace:Code:
Starting Macromedia JRun 4 (Build 84683), PDQ server
03/21 18:03:16 info JRun Naming Service listening on *:2909
03/21 18:03:17 warning No sessionSecret has been specified in jrun.xml. Installing a self generated sessionSecret.
03/21 18:03:17 info No JDBC data sources have been configured for this server (see jrun-resources.xml)
03/21 18:03:18 info JRun Web Server listening on *:80
03/21 18:03:18 info Deploying enterprise application "VQ-ear" from: file:/C:/JRun4/servers/PDQ/VQ-ear/
03/21 18:03:18 info Deploying web application "PDQ Administration Web Application" from: file:/C:/JRun4/servers/PDQ/VQ-ear/
03/21 18:03:19 info Web Services in VQ-ear#VQ-war:
03/21 18:03:19 info AdminService
03/21 18:03:19 info PDQDocWebService
03/21 18:03:19 info AxisSampleLoanCalcService
03/21 18:03:19 info PDQShipToWebService
03/21 18:03:19 warning VQ-war web application has 'reload' as true in jrun-web.xml. Consider setting it false if the application is running in production environment.
03/21 18:03:19 warning VQ-war web application has 'compile' as true in jrun-web.xml. Consider setting it false if the application is running in production environment.
03/21 18:03:19 user JSPServlet: init
03/21 18:03:20 info Deploying enterprise application "JRun 4.0 Internal J2EE Components" from: file:/C:/JRun4/lib/jrun-comp.ear
03/21 18:03:20 info Deploying EJB "JRunSQLInvoker" from: file:/C:/JRun4/lib/jrun-comp.ear
03/21 18:03:21 info Deploying enterprise application "Flash Remoting EAR" from: file:/C:/JRun4/lib/flashgateway.ear
03/21 18:03:21 info Deploying web application "Flash Remoting" from: file:/C:/JRun4/lib/flashgateway.ear
03/21 18:03:21 user JSPServlet: init
03/21 18:03:21 user FlashGatewayServlet: init
Server PDQ ready (startup time: 8 seconds)
03/21 18:03:43 user ServletInvoker: init
03/21 18:03:43 user hib.Test1HshipTo: init
- Hibernate 2.1.6
- loaded properties from resource hibernate.properties: {hibernate.connection.username=sa, hibernate.connection.password=meridian, hibernate.cglib.use_reflection_optimizer=false, hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect, hibernate.connection.url=jdbc:jtds:sqlserver://FMSUSQL2:1433/VisiDev, hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver}
- configuring from resource: /hibernate.cfg.xml
- Configuration resource: /hibernate.cfg.xml
- Mapping resource: hib/Message.hbm.xml
- Mapping class: hib.Message -> MESSAGES
- Mapping resource: com/fujimed/pdq/orm/HshipTo.hbm.xml
- Mapping class: com.fujimed.pdq.orm.HshipTo -> HShipTo
- Mapping resource: com/fujimed/pdq/orm/HshipTo2.hbm.xml
- Mapping class: com.fujimed.pdq.orm.HshipTo2 -> HShipTo2
- Mapping resource: com/fujimed/pdq/orm/Hrpgmstr.hbm.xml
- Mapping class: com.fujimed.pdq.orm.Hrpgmstr -> HRPGMstr
- Mapping resource: com/fujimed/pdq/orm/Hrmaster.hbm.xml
- Mapping class: com.fujimed.pdq.orm.Hrmaster -> HRMaster
- Mapping resource: com/fujimed/pdq/orm/Hcmaster.hbm.xml
- Mapping class: com.fujimed.pdq.orm.Hcmaster -> HCMaster
- Configured SessionFactory: null
- processing one-to-many association mappings
- Mapping collection: com.fujimed.pdq.orm.HshipTo.hrpgmstrs -> HRPGMstr
- processing one-to-one association property references
- processing foreign key constraints
- Using dialect: net.sf.hibernate.dialect.SQLServerDialect
- Use outer join fetching: true
- DBCP using driver: net.sourceforge.jtds.jdbc.Driver at URL: jdbc:jtds:sqlserver://FMSUSQL2:1433/VisiDev
- Connection properties: {user=sa, password=meridian}
- DBCP prepared statement pooling enabled
- No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
- Use scrollable result sets: true
- Use JDBC3 getGeneratedKeys(): true
- Optimize cache for minimal puts: false
- echoing all SQL to stdout
- Query language substitutions: {}
- cache provider: net.sf.hibernate.cache.EhCacheProvider
- instantiating and configuring caches
- building session factory
- Not binding factory to JNDI, no JNDI name configured
Hibernate: select hshipto0_.QuoteNum as QuoteNum1_, hshipto0_.Idx as Idx1_, hshipto0_.STName as STName1_, hshipto0_.STAddr1 as STAddr11_, hshipto0_.STAddr2 as STAddr21_, hshipto0_.STCity as STCity1_, hshipto0_.STState as STState1_, hshipto0_.STZip as STZip1_, hshipto0_.STAttn as STAttn1_, hshipto0_.STTitle as STTitle1_, hshipto0_.STPhone as STPhone1_, hshipto0_.STInfo as STInfo1_, hshipto0_.STCstNo as STCstNo1_, hshipto0_.STCstSfx as STCstSfx1_, hshipto21_.QuoteNum as QuoteNum0_, hshipto21_.DateStmp as DateStmp0_, hshipto21_.IDX as IDX0_, hshipto21_.STName as STName0_, hshipto21_.STAddr1 as STAddr10_, hshipto21_.STAddr2 as STAddr20_, hshipto21_.STCity as STCity0_, hshipto21_.STState as STState0_, hshipto21_.STZip as STZip0_, hshipto21_.STAttn as STAttn0_, hshipto21_.STTitle as STTitle0_, hshipto21_.STPhone as STPhone0_, hshipto21_.STInfo as STInfo0_, hshipto21_.STCstNo as STCstNo0_, hshipto21_.STCstSfx as STCstSfx0_, hshipto21_.QuoteNum as QuoteNum0_, hshipto21_.IDX as IDX0_ from HShipTo hshipto0_ left outer join HShipTo2 hshipto21_ on hshipto0_.QuoteNum=hshipto21_.QuoteNum and hshipto0_.Idx=hshipto21_.IDX where hshipto0_.QuoteNum=? and hshipto0_.Idx=?
Hibernate: select hshipto20_.QuoteNum as QuoteNum1_, hshipto20_.DateStmp as DateStmp1_, hshipto20_.IDX as IDX1_, hshipto20_.STName as STName1_, hshipto20_.STAddr1 as STAddr11_, hshipto20_.STAddr2 as STAddr21_, hshipto20_.STCity as STCity1_, hshipto20_.STState as STState1_, hshipto20_.STZip as STZip1_, hshipto20_.STAttn as STAttn1_, hshipto20_.STTitle as STTitle1_, hshipto20_.STPhone as STPhone1_, hshipto20_.STInfo as STInfo1_, hshipto20_.STCstNo as STCstNo1_, hshipto20_.STCstSfx as STCstSfx1_, hshipto20_.QuoteNum as QuoteNum1_, hshipto20_.IDX as IDX1_, hshipto1_.QuoteNum as QuoteNum0_, hshipto1_.Idx as Idx0_, hshipto1_.STName as STName0_, hshipto1_.STAddr1 as STAddr10_, hshipto1_.STAddr2 as STAddr20_, hshipto1_.STCity as STCity0_, hshipto1_.STState as STState0_, hshipto1_.STZip as STZip0_, hshipto1_.STAttn as STAttn0_, hshipto1_.STTitle as STTitle0_, hshipto1_.STPhone as STPhone0_, hshipto1_.STInfo as STInfo0_, hshipto1_.STCstNo as STCstNo0_, hshipto1_.STCstSfx as STCstSfx0_ from HShipTo2 hshipto20_ left outer join HShipTo hshipto1_ on hshipto20_.QuoteNum=hshipto1_.QuoteNum and hshipto20_.IDX=hshipto1_.Idx where hshipto20_.QuoteNum=? and hshipto20_.IDX=?
Hibernate: select hrpgmstrs0_.QuoteNum as QuoteNum__, hrpgmstrs0_.STIdx as STIdx__, hrpgmstrs0_.LNK1 as LNK1__, hrpgmstrs0_.QuoteNum as QuoteNum1_, hrpgmstrs0_.LNK1 as LNK11_, hrpgmstrs0_.ProdGrp as ProdGrp1_, hrpgmstrs0_.CtrctDis as CtrctDis1_, hrpgmstrs0_.AddDis as AddDis1_, hrpgmstrs0_.PGPrc as PGPrc1_, hrpgmstrs0_.Dept as Dept1_, hrpgmstrs0_.OkToDiscount as OkToDisc8_1_, hrpgmstrs0_.SynWB as SynWB1_, hrpgmstrs0_.QuoteNum as QuoteNum1_, hrpgmstrs0_.STIdx as STIdx1_, hrmaster1_.QuoteNum as QuoteNum0_, hrmaster1_.LNK1 as LNK10_, hrmaster1_.PARTNUM as PARTNUM0_, hrmaster1_.QTY as QTY0_, hrmaster1_.PRICE as PRICE0_, hrmaster1_.DESCRIP as DESCRIP0_, hrmaster1_.ConfigQuote as ConfigQu7_0_, hrmaster1_.Discount as Discount0_, hrmaster1_.PurchasePrice as Purchase9_0_, hrmaster1_.ExistingPt as ExistingPt0_, hrmaster1_.DisplayExisting as Display11_0_, hrmaster1_.OptPrt as OptPrt0_ from HRPGMstr hrpgmstrs0_ left outer join HRMaster hrmaster1_ on hrpgmstrs0_.QuoteNum=hrmaster1_.QuoteNum and hrpgmstrs0_.LNK1=hrmaster1_.LNK1 where hrpgmstrs0_.QuoteNum=? and hrpgmstrs0_.STIdx=?
Hibernate: select hrpgmstr0_.QuoteNum as QuoteNum3_, hrpgmstr0_.LNK1 as LNK13_, hrpgmstr0_.ProdGrp as ProdGrp3_, hrpgmstr0_.CtrctDis as CtrctDis3_, hrpgmstr0_.AddDis as AddDis3_, hrpgmstr0_.PGPrc as PGPrc3_, hrpgmstr0_.Dept as Dept3_, hrpgmstr0_.OkToDiscount as OkToDisc8_3_, hrpgmstr0_.SynWB as SynWB3_, hrpgmstr0_.QuoteNum as QuoteNum3_, hrpgmstr0_.STIdx as STIdx3_, hshipto1_.QuoteNum as QuoteNum0_, hshipto1_.Idx as Idx0_, hshipto1_.STName as STName0_, hshipto1_.STAddr1 as STAddr10_, hshipto1_.STAddr2 as STAddr20_, hshipto1_.STCity as STCity0_, hshipto1_.STState as STState0_, hshipto1_.STZip as STZip0_, hshipto1_.STAttn as STAttn0_, hshipto1_.STTitle as STTitle0_, hshipto1_.STPhone as STPhone0_, hshipto1_.STInfo as STInfo0_, hshipto1_.STCstNo as STCstNo0_, hshipto1_.STCstSfx as STCstSfx0_, hshipto22_.QuoteNum as QuoteNum1_, hshipto22_.DateStmp as DateStmp1_, hshipto22_.IDX as IDX1_, hshipto22_.STName as STName1_, hshipto22_.STAddr1 as STAddr11_, hshipto22_.STAddr2 as STAddr21_, hshipto22_.STCity as STCity1_, hshipto22_.STState as STState1_, hshipto22_.STZip as STZip1_, hshipto22_.STAttn as STAttn1_, hshipto22_.STTitle as STTitle1_, hshipto22_.STPhone as STPhone1_, hshipto22_.STInfo as STInfo1_, hshipto22_.STCstNo as STCstNo1_, hshipto22_.STCstSfx as STCstSfx1_, hshipto22_.QuoteNum as QuoteNum1_, hshipto22_.IDX as IDX1_, hrmaster3_.QuoteNum as QuoteNum2_, hrmaster3_.LNK1 as LNK12_, hrmaster3_.PARTNUM as PARTNUM2_, hrmaster3_.QTY as QTY2_, hrmaster3_.PRICE as PRICE2_, hrmaster3_.DESCRIP as DESCRIP2_, hrmaster3_.ConfigQuote as ConfigQu7_2_, hrmaster3_.Discount as Discount2_, hrmaster3_.PurchasePrice as Purchase9_2_, hrmaster3_.ExistingPt as ExistingPt2_, hrmaster3_.DisplayExisting as Display11_2_, hrmaster3_.OptPrt as OptPrt2_ from HRPGMstr hrpgmstr0_ left outer join HShipTo hshipto1_ on hrpgmstr0_.QuoteNum=hshipto1_.QuoteNum and hrpgmstr0_.STIdx=hshipto1_.Idx left outer join HShipTo2 hshipto22_ on hshipto1_.QuoteNum=hshipto22_.QuoteNum and hshipto1_.Idx=hshipto22_.IDX left outer join HRMaster hrmaster3_ on hrpgmstr0_.QuoteNum=hrmaster3_.QuoteNum and hrpgmstr0_.LNK1=hrmaster3_.LNK1 where hrpgmstr0_.QuoteNum=? and hrpgmstr0_.LNK1=?
- IllegalArgumentException in class: com.fujimed.pdq.orm.HrpgmstrPK, getter method of property: quoteNum
- Failed to lazily initialize a collection
net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.fujimed.pdq.orm.HrpgmstrPK.quoteNum
at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:110)
at net.sf.hibernate.type.ComponentType.getPropertyValue(ComponentType.java:179)
at net.sf.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:205)
at net.sf.hibernate.type.ComponentType.nullSafeGetValues(ComponentType.java:164)
at net.sf.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:151)
at net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:749)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:788)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:911)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:931)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2117)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1991)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1953)
at net.sf.hibernate.type.OneToOneType.resolveIdentifier(OneToOneType.java:71)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:204)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2205)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:315)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:93)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3268)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:195)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.isEmpty(Set.java:114)
at hib.Test1HshipTo.service(Test1HshipTo.java:59)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:249)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:168)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:457)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
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 net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:96)
... 38 more
- cannot access loading collection
net.sf.hibernate.LazyInitializationException: cannot access loading collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:191)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.iterator(Set.java:130)
at hib.Test1HshipTo.service(Test1HshipTo.java:59)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:249)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:168)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:457)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
net.sf.hibernate.LazyInitializationException: cannot access loading collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:191)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.iterator(Set.java:130)
at hib.Test1HshipTo.service(Test1HshipTo.java:59)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:249)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:168)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:457)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
03/21 18:04:33 error There is no web application configured to service your request
03/21 18:04:33 user NoWebappServlet: init
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelpHibernate version: Mapping documents:Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Name and version of the database you are using:The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code: