Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
I have some problems with xml export/import in Hibernate Version 3.0
...
<class name="admin.usermanagement.User" table="user" node="user">
<id name="userId" column="user_id" type="long">
<generator class="increment"/>
</id>
<property name="firstName" column="first_name" node="firstname"/>
<property name="lastName" column="last_name" node="lastname"/>
...
</class>
...
for xml export, the java code looks like this:
Transaction transaction = session.beginTransaction();
List users = dom4jSession.createQuery("from User").list();
...
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("usertable");
Iterator it = users.iterator();
while( it.hasNext() ){
Element elem = (Element) it.next();
root.add(elem);
}
...
the xml result of this export looks like this
<usertable>
<user>
<userId>1</userId>
<firstname>John</firstname>
<lastname>Clinton</lastname>
...
</user>
<user>
<userId>2</userId>
<firstname>Marc</firstname>
<lastname>Twain</lastname>
...
</user>
</usertable>
My first question: why do I get userId in the xml output ?
I can't use it for direct import because userId is defined to be auto generated.
I think, if I remove userId, this is the xml which i can import now.
So, for import, the java code looks like
SAXReader reader = new SAXReader();
Document doc = reader.read(file);
...
Session dom4jSession = session.openSession(EntityMode.DOM4J);
Transaction transaction = session.beginTransaction();
Iterator it = doc.selectNodes("//user").iterator();
while ( it.hasNext() ){
dom4jSession.saveOrUpdate(it.next());
}
transaction.commit();
This doesn't work.
I get an Exception: Unknown entity: user !?!?!?