Hi All,
I have a problem loading a Bean with Betwixt. I am loading a Person Bean
with Hibernate (DB Persistence tool) and passing the bean to Betwixt to O/P
the Bean in an XML format. The data is loaded from the DB (and I confirmed
the same) and when I call the BeanWriter to output the bean it throws me an
error:
What I am trying to do is, pass an entire Object to the BeanWriter so that I
could get the XML output for that Object.
Heres what I am doing:
========================================================================================
I have a PerspectiveResponse Bean with object as its property which looks
like this:
public class PerspectiveResponse {
private Object object;
public PerspectiveResponse() {
}
public PerspectiveResponse(Object object) {
setObject(object);
}
public Object getObject() {
return this.object;
}
public void setObject(Object object) {
this.object = object;
}
}
========================================================================
Main Class:
==========
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();
//THEN I INSTANTIATE A PERSON BEAN AND PASS IT TO BETWIXT TO GENERATE THE
XML OUTPUT
Person person = (Person) session.load(Person.class, id); //Dont worry about
this, its a Hibernate way of loading a Bean mapped with the DB table, and it
works perfect
beanWriter.write("perspectiveResponse", new PerspectiveResponse(person));
System.out.println( outputWriter.toString());
========================================================================
But if I run the Main I get an error:
java.lang.UnsupportedOperationException
Also if I simply set the properties of my Person Bean manually (not loading
values through Hibernate) I get the desired XML o/p, heres what I mean :
Person p = new Person();
p.setName("blah blah");
p.setId(1001);
beanWriter.write("perspectiveResponse", p);
System.out.println(outputWriter.toString());
========================================================================
<perspectiveResponse>
<Person>
<id> 1001 </id>
<name> blah blah </name>
.................
</Person>
</perspectiveResponse>
========================================================================
So I dont understand why doesnt the BeanWriter load the Bean with values
that are fetched from the DB via Hibernate ???
why is it throwing me with the ::::::::
java.lang.UnsupportedOperationException :::::::::::: exception
Is it something to do with the Session withing which I load the values from
the DB using Hibernate ???
Has anyone tried this combination before I mean Hibernate and Betwixt. All
suggestions are welcomed.
Thanks in advance,
-Sameer