Below is the mappings, code and stacktrace of my project
DEpfilesin and DDetails are a one to many relationship 1 Depfilesin could have many DDetails records
3770246 Is the value that is stored in DDetails.id I want it to use the value that is stored in DDetails.filesin_id when it does the link between the two How do i make it do this?
Code between sessionFactory.openSession() and session.close(): DTrns dtransObj = (DTrns)normalSession.load(DTrns.class,new Long(2290156)); System.out.println("DTRNS TRN ID " + dtransObj.getTrnID()); //LOADS DDetails List list = dtransObj.getdDetails(); if(list.size()>0) { Iterator it = list.iterator(); while(it.hasNext()) { DDetails dDetailsObj = (DDetails)it.next(); System.out.println("DDETAILS FILES_IN_ID " + dDetailsObj.getFilesInID()); //LOADS D_EPFilesIn Set dEpFilesInList = dDetailsObj.getdEpFilesIn(); if(dEpFilesInList!=null && (dEpFilesInList.size()>0)) { Iterator et = dEpFilesInList.iterator(); while(et.hasNext()) { DEpFilesIn dEpFilesInObj = (DEpFilesIn)et.next(); System.out.println("DEPFILESIN FILES ID " + dEpFilesInObj.getFilesId() + " ID " + dEpFilesInObj.getId()); } } } } System.out.println("");
Full stack trace of any exception that occurs: 1516 [main] ERROR collection.PersistentCollection - Failed to lazily initialize a collection net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 3770246, of class: DEpFilesIn at net.sf.hibernate.impl.SessionImpl.throwObjectNotFound(SessionImpl.java:1663) at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1702) at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:62) at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1933) at net.sf.hibernate.loader.Loader.doFind(Loader.java:184) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:492) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:90) at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2734) at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:140) at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:60) at net.sf.hibernate.collection.Bag.size(Bag.java:194) at XMLTest.getQuery(XMLTest.java:85) at XMLTest.main(XMLTest.java:229) 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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:78) net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 3770246, of class: DEpFilesIn at net.sf.hibernate.impl.SessionImpl.throwObjectNotFound(SessionImpl.java:1663) at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1702) at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:62) at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1933) at net.sf.hibernate.loader.Loader.doFind(Loader.java:184) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:492) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:90) at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2734) at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:140) at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:60) at net.sf.hibernate.collection.Bag.size(Bag.java:194) at XMLTest.getQuery(XMLTest.java:85) at XMLTest.main(XMLTest.java:229) 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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:78) rethrown as net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection: No row with the given identifier exists: 3770246, of class: DEpFilesIn at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:152) at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:60) at net.sf.hibernate.collection.Bag.size(Bag.java:194) at XMLTest.getQuery(XMLTest.java:85) at XMLTest.main(XMLTest.java:229) 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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:78) Caused by: net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 3770246, of class: DEpFilesIn at net.sf.hibernate.impl.SessionImpl.throwObjectNotFound(SessionImpl.java:1663) at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1702) at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:62) at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1933) at net.sf.hibernate.loader.Loader.doFind(Loader.java:184) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:492) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:90) at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2734) at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:140) ... 9 more
Name and version of the database you are using: MYSQL 3.23.38-nt
Sagar Bilgi
Ranch Hand
Joined: Apr 26, 2001
Posts: 37
posted
0
Try again by removing the inverse = true.if that doent work then try removing both lazy = true and inverse -"true" from the files. I had the same problem and it worked after I removed the inverse=true from the parent side.