I'm trying to isolate the problem. I am using the following seemingly simple code snippet. Is there a problem referencing the META-INF/persistence.xml file through ClassLoader.getResource() in JWS? I've spent a good day on this now, if anyone can at least give me a "yes, I've done it, it should work", at least I'll know that it's possible. Otherwise, should it be submitted as a JIRA issue with Hibernate EntityManager? Thanks,
Mark
EntityManager em;
try {
// get a new entity manager factory
Map<String, String> properties = new HashMap<String, String>();
properties.put("hibernate.connection.driver_class", "net.sourceforge.jtds.jdbc.Driver");
properties.put("hibernate.connection.url", "jdbc:jtds:sqlserver://dbserver/testdb;tds=8.0;lastupdatecount=true");
properties.put("hibernate.connection.username", "xxxxxxx");
properties.put("hibernate.connection.password", "xxxxxxx");
properties.put("hibernate.show_sql", "false");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("ejb-test", properties);
// test properties
em = emf.createEntityManager();
Query q = em.createQuery("select a from Account a where a.id = 10");
List<Account> list = q.getResultList();
Account a = list.get(0);
em.close();
System.err.println("list size = " + list.size());
System.err.println("accountType = " + a.getAccountType());
System.err.println("name = " + a.getName());
// close the factory
emf.close();
}
catch (Exception e) {
throw new RuntimeException(e);
}
which produces the following exception in Java Web Start (works fine from desktop):
java.lang.RuntimeException: javax.persistence.PersistenceException: java.lang.NullPointerException
at hibernatetest.Main.<init>(Main.java:61)
at hibernatetest.Main.main(Main.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.persistence.PersistenceException: java.lang.NullPointerException
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:217)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at hibernatetest.Main.<init>(Main.java:45)
... 12 more
Caused by: java.lang.NullPointerException
at java.io.File.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at org.hibernate.ejb.packaging.FileZippedJarVisitor.doProcessElements(FileZippedJarVisitor.java:34)
at org.hibernate.ejb.packaging.JarVisitor.getMatchingEntries(JarVisitor.java:208)
at org.hibernate.ejb.Ejb3Configuration.addMetadataFromVisitor(Ejb3Configuration.java:223)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:200)
... 15 more
|