Trying this, and I'm getting a "No tuplizer found for entity-mode [DOM4J]" error.
I suspect I need to add XML-entity annotations to my annotated POJO???? I've tried searching but I can't find where the XML-entity annotation extensions are (if they in fact exist).
Here's the annotated POJO:
Code:
@Entity (access = AccessType.FIELD)
public class State
implements java.io.Serializable
{
@Id (generate = GeneratorType.NONE)
@Column (length = 2)
protected String key ;
@Column (length = 64)
protected String name ;
public State (String key, String name)
{
this.key = key ;
this.name = name ;
}
public String getKey () { return this.key ; }
public void setKey (String p) { this.key = p ; }
...
}
Here's the data access code:
Code:
public static void main (String [] args)
{
Transaction tx = null ;
Session session = null ;
try {
Document document = DocumentHelper.createDocument();
Element root = document.addElement ("root");
Configuration configuration = new AnnotationConfiguration() ;
configuration.configure() ;
SessionFactory factory = configuration.buildSessionFactory();
session = factory.openSession();
Session dom4jSession = session.getSession (EntityMode.DOM4J) ;
tx = dom4jSession.beginTransaction () ;
Element element = (Element) dom4jSession.get (State.class, "NY") ;
root.add (element) ;
document.write (new FileWriter ("test.xml")) ;
}
catch (Exception e) {
e.printStackTrace () ;
}
finally {
if (tx != null)
tx.commit () ;
if (session != null)
session.close () ;
}
}