Hi All,
I am loading a DB record via Hibernate using this:
Person person = (Person) session.load(Person.class,5667);
and then trying to output the Person Bean into an XML format using Apache Commons Betwixt like this:
Main Class:
Code:
BeanWriter beanWriter;
StringWriter outputWriter;
//THIS IS HOW I CONFIGURE BETWIXT TO GET MY DESIRED XML OUTPUT
outputWriter = new StringWriter();
// For well-formed xml, we need to add the prolog
outputWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
// Create a BeanWriter which writes to our prepared stream
beanWriter = new BeanWriter(outputWriter);
//Tweaked configuration for getting desired XML o/p for XML SearchResponse
beanWriter.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(false);
beanWriter.getBindingConfiguration().setMapIDs(true);
beanWriter.enablePrettyPrint();
beanWriter.write("perspectiveResponse", new PerspectiveResponse(person));
System.out.println( outputWriter.toString());
But when I run my Main class it gives me an error:
java.lang.UnsupportedOperationException
at org.hibernate.util.IdentityMap.keySet(IdentityMap.java:162)
at org.hibernate.stat.SessionStatisticsImpl.getEntityCount(SessionStatisticsImpl.java:21)
at org.hibernate.stat.SessionStatisticsImpl.toString(SessionStatisticsImpl.java:37)
at java.lang.String.valueOf(String.java:2577)
at java.lang.StringBuffer.append(StringBuffer.java:220)
at org.apache.commons.betwixt.io.AbstractBeanWriter.pushBean(AbstractBeanWriter.java:1019)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBeanWriter.java:348)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBeanWriter.java:267)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeElementContent(AbstractBeanWriter.java:945)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeElement(AbstractBeanWriter.java:820)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBeanWriter.java:362)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBeanWriter.java:267)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeElementContent(AbstractBeanWriter.java:945)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeElement(AbstractBeanWriter.java:820)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBeanWriter.java:362)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBeanWriter.java:267)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeElementContent(AbstractBeanWriter.java:936)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeElement(AbstractBeanWriter.java:820)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBeanWriter.java:362)
at org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBeanWriter.java:243)
at org.apache.commons.betwixt.io.AbstractBeanWriter.write(AbstractBeanWriter.java:174)
at com.mms.HibernateTest.main(HibernateTest.java:74)
I am not sure why Hibernate is throwing me this error. Has anybody worked on the combination of Hibernate and Betwixt before ??? ( I mean loading a Bean with Hibernate and outputing it via Betwixt)
Did anyone come across through this problem?
All help and suggestions are greatly appreciate !!!
Thanks
Sam