From: <leg...@at...> - 2003-09-09 12:27:36
|
Message: A new issue has been created in JIRA. --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?= key=3DHB-320 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-320 Summary: Allow java.beans.XMLEncoder to process persisted classes posse= ssing collections Type: Improvement Status: Unassigned Priority: Minor Project: Hibernate2 Components:=20 core Versions: 2.1 beta 3 Assignee:=20 Reporter: Roberto S. Tyley Created: Tue, 9 Sep 2003 7:27 AM Updated: Tue, 9 Sep 2003 7:27 AM Environment: Win 2000, JDK 1.4.2 Description: java.beans.XMLEncoder was introduced in J2SE v1.4, and provides a convenien= t method of serialising an object graph to an XML file: http://java.sun.com/j2se/1.4.2/docs/api/java/beans/XMLEncoder.html It would be nice to be able to extract a copy of the information stored in = a hibernate database as an XML file, ie. by doing a hibernate query to get = the information you want (possibly "from o in class java.lang.Object", or w= hatever), and translate this object graph to XML using XMLEncoder. Unfortun= ately, this approach does not work in the common case of persisted classes = possessing collections - a LazyInitializationException is raised processing= the collection (an example trace is included below). This exception occurs= even if your session is still open, in fact even if you disable lazy initi= alization, because of the approach used by XMLEncoder to check for circular= ities in the object graph. When asked to persist an object, XMLEncoder appe= ars to instantiate a new instance of that class, to allow it to check if it= already has a suitable previous reference to the object (see java.beans.Pe= rsistenceDelegate.writeObject()). Unfortunately, when a net.sf.hibernate.co= llection.PersistentCollection has this treatment, the instantiatation of th= e new instance does not appear supply it with a reference to the Session ob= ject- XMLEncoder's further attempts to query the state of the collection fa= il with a LazyInitializationException. If your object graph has yet to be p= ersisted, ie. the collections in it are still vanilla HashMaps, etc, the XM= LEncoder will work fine. XMLEncoder is intended to be a JavaBean serialiser, and as Hibernate persis= ted classes have to conform to the JavaBean pattern, you'd expect the XMLEn= coder to work well here - is there a possibility of allowing this to happen= ? I think one possible line of attack may be providing a series of java.bea= ns.PersistenceDelegate classes to handle hibernate collections - any other = ideas?! cheers, Roberto ----- Trace follows below: net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a= collection - no Session =09at net.sf.hibernate.collection.PersistentCollection.initialize(Persisten= tCollection.java:164) =09at net.sf.hibernate.collection.PersistentCollection.read(PersistentColle= ction.java:63) =09at net.sf.hibernate.collection.Set.size(Set.java:108) =09at java.util.AbstractSet.equals(AbstractSet.java:72) =09at java.beans.DefaultPersistenceDelegate.equals(DefaultPersistenceDelega= te.java:207) =09at java.beans.DefaultPersistenceDelegate.doProperty(DefaultPersistenceDe= legate.java:220) =09at java.beans.DefaultPersistenceDelegate.initBean(DefaultPersistenceDele= gate.java:254) =09at java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDe= legate.java:395) =09at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:1= 03) =09at java.beans.Encoder.writeObject(Encoder.java:55) =09at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250) =09at java.beans.Encoder.writeExpression(Encoder.java:260) =09at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363) =09at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:1= 00) =09at java.beans.Encoder.writeObject(Encoder.java:55) =09at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250) =09at java.beans.Encoder.writeObject1(Encoder.java:192) =09at java.beans.Encoder.cloneStatement(Encoder.java:205) =09at java.beans.Encoder.writeStatement(Encoder.java:236) =09at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:326) =09at java.beans.DefaultPersistenceDelegate.invokeStatement(DefaultPersiste= nceDelegate.java:242) =09at java.beans.java_util_List_PersistenceDelegate.initialize(MetaData.jav= a:245) =09at java.beans.PersistenceDelegate.initialize(PersistenceDelegate.java:19= 1) =09at java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDe= legate.java:393) =09at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:1= 03) =09at java.beans.Encoder.writeObject(Encoder.java:55) =09at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250) =09at java.beans.Encoder.writeExpression(Encoder.java:260) =09at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:363) =09at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:1= 00) =09at java.beans.Encoder.writeObject(Encoder.java:55) =09at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250) =09at java.beans.Encoder.writeObject1(Encoder.java:192) =09at java.beans.Encoder.cloneStatement(Encoder.java:205) =09at java.beans.Encoder.writeStatement(Encoder.java:236) =09at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:326) =09at java.beans.XMLEncoder.writeObject(XMLEncoder.java:253) =09at com.thisbedisonfire.madgag.Main.main(Main.java:88) --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators= .jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |