Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Hibernate 3.0
Mapping documents:
Code:
<class name="Wine"
table="wine"
node="wine" >
<id name="id"
node="@id"
type="long"
unsaved-value="null"
column="WINE_ID" >
<generator class="hilo">
<param name="table">HI_VALUE</param>
<param name="column">NEXT_VALUE</param>
<param name="max_lo">100</param>
</generator>
</id>
<list
name="reviews"
node="reviews"
embed-xml="true"
cascade="save-update"
inverse="true"
lazy="true">
<key column="WINE_ID"/>
<list-index column="WINEREVIEW_INDEX"/>
<one-to-many
class="Review"
embed-xml="false"
node="review/@id"
/>
</list>
...
Code between sessionFactory.openSession() and session.close():Code:
Session session = HibernateUtil.currentSession();
Session s = session.getSession(EntityMode.DOM4J);
List results = s.createQuery("from Wine wine ").list();
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("root");
for (Iterator i = results.iterator(); i.hasNext();) {
Element e = (Element) i.next();
log.debug("node count="+root.nodeCount());
root.add(e);
}
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(new FileWriter("test.xml"), format);
writer.write(doc);
writer.close();
Name and version of the database you are using:MySQL 4.1.7-nt
I am exporting objects to XML. When I try to export a collection that is a one-to-many, it doesn't seem to recognize the /@id syntax:
Code:
<root>
<wine id="1010">
<reviews>
<review/@id>1212</review/@id>
</reviews>
</wine>
</root>
Am I doing something wrong? Or is this a bug?
Thanks,
Dave