-->
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: XMLEncoder and Hibernate? LazyInitializationException
PostPosted: Tue Jun 09, 2009 9:02 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi, even I had set everything to eager and/or tried to wrap around a session/transaction. I still get a LazyInitializationException (stack trace see below) if I tried to store objects loaded from the db to an xml-file.

Does PersitentBag, PersitentList and so on don't work with XML-Encoder? Or do I have to specify an Persitence-Delegate for them? Cause Hibernate don't replace them, even the whole list was loaded before. Or do you have any other idea to get to work. Or is there any easy way to convert any subclass of PersistentCollection to java.util classes?

Thanks.

Greetings Michael


Code:
14:38:00,765 DEBUG SQL:401 - select taxes0_.Steuerdaten_id as Steuerda1_4_, taxes0_.taxes_id as taxes2_4_, taxes0_.SO_Pos as SO3_4_, steuerobje1_.id as id4_0_, steuerobje1_.anteilAusgabenProduktion as anteilAu2_4_0_, steuerobje1_.anteilAusgabenVertrieb as anteilAu3_4_0_, steuerobje1_.anteilAusgabenVerwaltung as anteilAu4_4_0_, steuerobje1_.VERSION_OPTLOCK as VERSION5_4_0_, steuerobje1_.collectionComponent_id as collecti8_5_0_, steuerobje1_.comment as comment5_0_, steuerobje1_.hkTax_id as hkTax9_5_0_, steuerobje1_.inHK as inHK5_0_, steuerobje1_.lastPeriod as lastPeriod5_0_, steuerobje1_.liquiWirksam as liquiWir4_5_0_, steuerobje1_.name as name5_0_, steuerobje1_.perioden as perioden5_0_, steuerobje1_.type as type5_0_, taxbasesam2_.id as id18_1_, taxbasesam2_.bmgTyp as bmgTyp18_1_, taxbasesam2_.comment as comment18_1_, taxbasesam2_.name as name18_1_, taxbasesam2_.tarifImp_id as tarifImp2_21_1_, taxbasesam2_.taxbase as taxbase21_1_, universalt3_.id as id6_2_, universalt3_.additiveLevels as additive3_6_2_, universalt3_.comment as comment6_2_, universalt3_.inflation as inflation6_2_, universalt3_.selfDeductible as selfDedu6_6_2_, universalt3_.storageName as storageN7_6_2_, universalt3_.tarifOfTax as tarifOfTax6_2_, universalt3_.TarifArt as TarifArt6_2_, valueprodu4_.id as id13_3_, valueprodu4_.commentary as commentary13_3_, valueprodu4_.funktion as funktion13_3_, valueprodu4_.einbezogen as einbezogen14_3_, valueprodu4_.einbezogenAS as einbezog2_14_3_ from Steuerdaten_SteuerObjekt taxes0_ left outer join SteuerObjekt steuerobje1_ on taxes0_.taxes_id=steuerobje1_.id left outer join TaxBaseSammelbaustein taxbasesam2_ on steuerobje1_.collectionComponent_id=taxbasesam2_.id left outer join UniversalTarif universalt3_ on taxbasesam2_.tarifImp_id=universalt3_.id left outer join ValueProductionCosts valueprodu4_ on steuerobje1_.hkTax_id=valueprodu4_.id where taxes0_.Steuerdaten_id=?
12781 [AWT-EventQueue-0] DEBUG org.hibernate.SQL  - select taxes0_.Steuerdaten_id as Steuerda1_4_, taxes0_.taxes_id as taxes2_4_, taxes0_.SO_Pos as SO3_4_, steuerobje1_.id as id4_0_, steuerobje1_.anteilAusgabenProduktion as anteilAu2_4_0_, steuerobje1_.anteilAusgabenVertrieb as anteilAu3_4_0_, steuerobje1_.anteilAusgabenVerwaltung as anteilAu4_4_0_, steuerobje1_.VERSION_OPTLOCK as VERSION5_4_0_, steuerobje1_.collectionComponent_id as collecti8_5_0_, steuerobje1_.comment as comment5_0_, steuerobje1_.hkTax_id as hkTax9_5_0_, steuerobje1_.inHK as inHK5_0_, steuerobje1_.lastPeriod as lastPeriod5_0_, steuerobje1_.liquiWirksam as liquiWir4_5_0_, steuerobje1_.name as name5_0_, steuerobje1_.perioden as perioden5_0_, steuerobje1_.type as type5_0_, taxbasesam2_.id as id18_1_, taxbasesam2_.bmgTyp as bmgTyp18_1_, taxbasesam2_.comment as comment18_1_, taxbasesam2_.name as name18_1_, taxbasesam2_.tarifImp_id as tarifImp2_21_1_, taxbasesam2_.taxbase as taxbase21_1_, universalt3_.id as id6_2_, universalt3_.additiveLevels as additive3_6_2_, universalt3_.comment as comment6_2_, universalt3_.inflation as inflation6_2_, universalt3_.selfDeductible as selfDedu6_6_2_, universalt3_.storageName as storageN7_6_2_, universalt3_.tarifOfTax as tarifOfTax6_2_, universalt3_.TarifArt as TarifArt6_2_, valueprodu4_.id as id13_3_, valueprodu4_.commentary as commentary13_3_, valueprodu4_.funktion as funktion13_3_, valueprodu4_.einbezogen as einbezogen14_3_, valueprodu4_.einbezogenAS as einbezog2_14_3_ from Steuerdaten_SteuerObjekt taxes0_ left outer join SteuerObjekt steuerobje1_ on taxes0_.taxes_id=steuerobje1_.id left outer join TaxBaseSammelbaustein taxbasesam2_ on steuerobje1_.collectionComponent_id=taxbasesam2_.id left outer join UniversalTarif universalt3_ on taxbasesam2_.tarifImp_id=universalt3_.id left outer join ValueProductionCosts valueprodu4_ on steuerobje1_.hkTax_id=valueprodu4_.id where taxes0_.Steuerdaten_id=?
14:38:17,468 ERROR LazyInitializationException:19 - failed to lazily initialize a collection, no session or session was closed
org.hibernate.14:38:00,765 DEBUG SQL:401 - select taxes0_.Steuerdaten_id as Steuerda1_4_, taxes0_.taxes_id as taxes2_4_, taxes0_.SO_Pos as SO3_4_, steuerobje1_.id as id4_0_, steuerobje1_.anteilAusgabenProduktion as anteilAu2_4_0_, steuerobje1_.anteilAusgabenVertrieb as anteilAu3_4_0_, steuerobje1_.anteilAusgabenVerwaltung as anteilAu4_4_0_, steuerobje1_.VERSION_OPTLOCK as VERSION5_4_0_, steuerobje1_.collectionComponent_id as collecti8_5_0_, steuerobje1_.comment as comment5_0_, steuerobje1_.hkTax_id as hkTax9_5_0_, steuerobje1_.inHK as inHK5_0_, steuerobje1_.lastPeriod as lastPeriod5_0_, steuerobje1_.liquiWirksam as liquiWir4_5_0_, steuerobje1_.name as name5_0_, steuerobje1_.perioden as perioden5_0_, steuerobje1_.type as type5_0_, taxbasesam2_.id as id18_1_, taxbasesam2_.bmgTyp as bmgTyp18_1_, taxbasesam2_.comment as comment18_1_, taxbasesam2_.name as name18_1_, taxbasesam2_.tarifImp_id as tarifImp2_21_1_, taxbasesam2_.taxbase as taxbase21_1_, universalt3_.id as id6_2_, universalt3_.additiveLevels as additive3_6_2_, universalt3_.comment as comment6_2_, universalt3_.inflation as inflation6_2_, universalt3_.selfDeductible as selfDedu6_6_2_, universalt3_.storageName as storageN7_6_2_, universalt3_.tarifOfTax as tarifOfTax6_2_, universalt3_.TarifArt as TarifArt6_2_, valueprodu4_.id as id13_3_, valueprodu4_.commentary as commentary13_3_, valueprodu4_.funktion as funktion13_3_, valueprodu4_.einbezogen as einbezogen14_3_, valueprodu4_.einbezogenAS as einbezog2_14_3_ from Steuerdaten_SteuerObjekt taxes0_ left outer join SteuerObjekt steuerobje1_ on taxes0_.taxes_id=steuerobje1_.id left outer join TaxBaseSammelbaustein taxbasesam2_ on steuerobje1_.collectionComponent_id=taxbasesam2_.id left outer join UniversalTarif universalt3_ on taxbasesam2_.tarifImp_id=universalt3_.id left outer join ValueProductionCosts valueprodu4_ on steuerobje1_.hkTax_id=valueprodu4_.id where taxes0_.Steuerdaten_id=?
12781 [AWT-EventQueue-0] DEBUG org.hibernate.SQL  - select taxes0_.Steuerdaten_id as Steuerda1_4_, taxes0_.taxes_id as taxes2_4_, taxes0_.SO_Pos as SO3_4_, steuerobje1_.id as id4_0_, steuerobje1_.anteilAusgabenProduktion as anteilAu2_4_0_, steuerobje1_.anteilAusgabenVertrieb as anteilAu3_4_0_, steuerobje1_.anteilAusgabenVerwaltung as anteilAu4_4_0_, steuerobje1_.VERSION_OPTLOCK as VERSION5_4_0_, steuerobje1_.collectionComponent_id as collecti8_5_0_, steuerobje1_.comment as comment5_0_, steuerobje1_.hkTax_id as hkTax9_5_0_, steuerobje1_.inHK as inHK5_0_, steuerobje1_.lastPeriod as lastPeriod5_0_, steuerobje1_.liquiWirksam as liquiWir4_5_0_, steuerobje1_.name as name5_0_, steuerobje1_.perioden as perioden5_0_, steuerobje1_.type as type5_0_, taxbasesam2_.id as id18_1_, taxbasesam2_.bmgTyp as bmgTyp18_1_, taxbasesam2_.comment as comment18_1_, taxbasesam2_.name as name18_1_, taxbasesam2_.tarifImp_id as tarifImp2_21_1_, taxbasesam2_.taxbase as taxbase21_1_, universalt3_.id as id6_2_, universalt3_.additiveLevels as additive3_6_2_, universalt3_.comment as comment6_2_, universalt3_.inflation as inflation6_2_, universalt3_.selfDeductible as selfDedu6_6_2_, universalt3_.storageName as storageN7_6_2_, universalt3_.tarifOfTax as tarifOfTax6_2_, universalt3_.TarifArt as TarifArt6_2_, valueprodu4_.id as id13_3_, valueprodu4_.commentary as commentary13_3_, valueprodu4_.funktion as funktion13_3_, valueprodu4_.einbezogen as einbezogen14_3_, valueprodu4_.einbezogenAS as einbezog2_14_3_ from Steuerdaten_SteuerObjekt taxes0_ left outer join SteuerObjekt steuerobje1_ on taxes0_.taxes_id=steuerobje1_.id left outer join TaxBaseSammelbaustein taxbasesam2_ on steuerobje1_.collectionComponent_id=taxbasesam2_.id left outer join UniversalTarif universalt3_ on taxbasesam2_.tarifImp_id=universalt3_.id left outer join ValueProductionCosts valueprodu4_ on steuerobje1_.hkTax_id=valueprodu4_.id where taxes0_.Steuerdaten_id=?
14:38:17,468 ERROR LazyInitializationException:19 - failed to lazily initialize a collection, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentList.listIterator(PersistentList.java:347)
   at java.util.AbstractList.equals(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.equals(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.doProperty(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.initBean(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.initialize(Unknown Source)
   at java.beans.PersistenceDelegate.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at java.beans.Encoder.writeExpression(Unknown Source)
   at java.beans.XMLEncoder.writeExpression(Unknown Source)
   at java.beans.PersistenceDelegate.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject1(Unknown Source)
   at java.beans.Encoder.cloneStatement(Unknown Source)
   at java.beans.Encoder.writeStatement(Unknown Source)
   at java.beans.XMLEncoder.writeStatement(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.invokeStatement(Unknown Source)
   at java.beans.java_util_Collection_PersistenceDelegate.initialize(Unknown Source)
   at java.beans.PersistenceDelegate.initialize(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.initialize(Unknown Source)
   at java.beans.PersistenceDelegate.initialize(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.initialize(Unknown Source)
   at java.beans.PersistenceDelegate.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at java.beans.Encoder.writeExpression(Unknown Source)
   at java.beans.XMLEncoder.writeExpression(Unknown Source)
   at java.beans.PersistenceDelegate.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject1(Unknown Source)
   at java.beans.Encoder.cloneStatement(Unknown Source)
   at java.beans.Encoder.writeStatement(Unknown Source)
   at java.beans.XMLEncoder.writeStatement(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at de.zew.vitax.gui.main.menu.sim.ModellMenu$4.doWork(ModellMenu.java:385)
   at de.zew.vitax.io.XML_WriteOperations.openXMLEncoder(XML_WriteOperations.java:278)
   at de.zew.vitax.io.XML_WriteOperations.access$1(XML_WriteOperations.java:232)
   at de.zew.vitax.io.XML_WriteOperations$2.run(XML_WriteOperations.java:423)
: failed to lazily initialize a collection, no session or session was closed
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentList.listIterator(PersistentList.java:347)
   at java.util.AbstractList.equals(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.equals(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.doProperty(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.initBean(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.initialize(Unknown Source)
   at java.beans.PersistenceDelegate.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at java.beans.Encoder.writeExpression(Unknown Source)
   at java.beans.XMLEncoder.writeExpression(Unknown Source)
   at java.beans.PersistenceDelegate.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject1(Unknown Source)
   at java.beans.Encoder.cloneStatement(Unknown Source)
   at java.beans.Encoder.writeStatement(Unknown Source)
   at java.beans.XMLEncoder.writeStatement(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.invokeStatement(Unknown Source)
   at java.beans.java_util_Collection_PersistenceDelegate.initialize(Unknown Source)
   at java.beans.PersistenceDelegate.initialize(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.initialize(Unknown Source)
   at java.beans.PersistenceDelegate.initialize(Unknown Source)
   at java.beans.DefaultPersistenceDelegate.initialize(Unknown Source)
   at java.beans.PersistenceDelegate.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at java.beans.Encoder.writeExpression(Unknown Source)
   at java.beans.XMLEncoder.writeExpression(Unknown Source)
   at java.beans.PersistenceDelegate.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at java.beans.Encoder.writeObject1(Unknown Source)
   at java.beans.Encoder.cloneStatement(Unknown Source)
   at java.beans.Encoder.writeStatement(Unknown Source)
   at java.beans.XMLEncoder.writeStatement(Unknown Source)
   at java.beans.XMLEncoder.writeObject(Unknown Source)
   at de.zew.vitax.gui.main.menu.sim.ModellMenu$4.doWork(ModellMenu.java:385)
   at de.zew.vitax.io.XML_WriteOperations.openXMLEncoder(XML_WriteOperations.java:278)
   at de.zew.vitax.io.XML_WriteOperations.access$1(XML_WriteOperations.java:232)
   at de.zew.vitax.io.XML_WriteOperations$2.run(XML_WriteOperations.java:423)



Top
 Profile  
 
 Post subject: Re: XMLEncoder and Hibernate? LazyInitializationException
PostPosted: Fri Jun 19, 2009 12:10 pm 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Bumping. Any ideas?

Thanks.

Greetings Michael


Top
 Profile  
 
 Post subject: Re: XMLEncoder and Hibernate? LazyInitializationException
PostPosted: Mon Jun 22, 2009 10:46 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi, according to
Using XMLEncoder
the XMLEncoder relies on java.util.AbstractList.

Hibernate doesn't use java.util.AbstractList according to the API, or?

Quote:
Persistence delegates for classes that implement List and Map

An internal persistence delegate for the AbstractList class has been provided that performs strictly correct initialization of the AbstractList class and its derivatives (including the java.util.Vector class) by not making any assumptions about initial state. The interested reader is recommended to look at the source code of the package-private java.beans.MetaData, which contains all the internal persistence delegates used by XMLEncoder -- including delegates that may be used for classes implementing the java.util.List and java.util.Map interfaces. These delegates are installed in XMLEncoder so that they will automatically be applied to all instances of java.util.AbstractList, java.util.AbstractMap, java.util.Hashtable, and their derivatives. They may be declared to apply to other classes implementing these interfaces as follows:

XMLEncoder e = new XMLEncoder(System.out);
e.setPersistenceDelegate(MyList.class,
e.getPersistenceDelegate(List.class));
e.writeObject( ... );


So I tried:

Code:
enc.setPersistenceDelegate(PersistentList.class, enc.getPersistenceDelegate(List.class));
enc.setPersistenceDelegate(PersistentBag.class, enc.getPersistenceDelegate(List.class));
   enc.setPersistenceDelegate(PersistentIdentifierBag.class, enc.getPersistenceDelegate(List.class));

   enc.setPersistenceDelegate(PersistentMap.class, enc.getPersistenceDelegate(Map.class));

   enc.setPersistenceDelegate(PersistentSet.class, enc.getPersistenceDelegate(Set.class));


But it didn't worked, same problem as above.
Even if I ensure an open session, it seems that the session is closed, by any operation in the meantime.

Any suggestions?

Do I have to implement it on my own (java.beans.MetaData)?
If yes, how should I do that?

Thanks a lot in advance.

Greetings Michael


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.