I'm trying to run embedded EJB 3.0 as an eclipse plugin, and I'm having a problem with the EntityManager.
Here is the setup: Plugin com.osc.core.ejb: I created a plugin project and copied the entire lib drectory from the EJB 3.0 embedded download into the root of that project. I added every jar file to the classpath in the runtime section of the MANIFEST.MF. I also exported every package. I also added: Eclipse-BuddyPolicy: registered to the MANIFEST.MF by hand Plugin com.osc.proto: I created a plugin and added com.osc.core.ejb as a dependency in the MANIFEST.MF. I copied the entire conf directory from the EJF 3.0 embedded download into the root of that project. I added the conf directory to the classpath in the runtime sectio of the MANIFEST.MF. I also added the buddy registry entry and "." to the classpath by hand so that I have: Eclipse-RegisterBuddy: com.osc.core.ejb Bundle-classPath: conf/, . in the MANIFEST.MF I created (in com.osc.proto) the following entity bean: | package com.osc.proto; | | import java.io.Serializable; | | import javax.persistence.Basic; | import javax.persistence.Entity; | import javax.persistence.GeneratedValue; | import javax.persistence.GenerationType; | import javax.persistence.Id; | import javax.persistence.Table; | | @Entity | @Table(name="USERS") | public class User implements Serializable | { | public int getId() | { | return id; | } | | public void setId(int id) | { | this.id = id; | } | | public String getName() | { | return name; | } | | public void setName(String name) | { | this.name = name; | } | | @Id | @GeneratedValue(strategy=GenerationType.AUTO) | private int id; | | @Basic | private String name; | | private static final long serialVersionUID = -49617049545463116L; | } | | I created the following platform runnable extension: | | package com.osc.proto; | | import javax.persistence.EntityManager; | import javax.persistence.PersistenceContext; | | import org.eclipse.core.runtime.IPlatformRunnable; | | public class PlatformRunnable implements IPlatformRunnable | { | public Object run(Object args) throws Exception | { | System.out.println("Starting application"); | User user = new User(); | user.setName("Bryan"); | System.out.println("Persisting user"); | manager.persist(user); | | System.out.println("All done"); | return null; | } | | @PersistenceContext(unitName="test") | public EntityManager manager; | } | | In the start method of the activator, I have: | | public void start(BundleContext context) throws Exception { | super.start(context); | System.out.println("Starting embedded EJB3"); | EJB3StandaloneBootstrap.boot(null); | EJB3StandaloneBootstrap.scanClasspath(); | | try | { | Persistence.createEntityManagerFactory("test"); | } | catch (Exception e) | { | System.out.println(e); | e.printStackTrace(); | } | } | | I have the following persistence.xml in the META-INF folder of that plugin: | <persistence> | <persistence-unit name="test"> | <jta-data-source>java:/DefaultDS</jta-data-source> | <properties> | <property name="hibernate.hbm2ddl.auto" value="create-drop"/> | </properties> | </persistence-unit> | </persistence> | When I run the platform runnable, I get the following exception when the activator starts and attempts to create the entity manager factory: Starting embedded EJB3 WARN 25-02 10:03:38,190 (BeanSchemaBinding.java:init:227) -You should use the 2.0 version of the Microcontainer xml. xmlns='urn:jboss:bean-deployer:2.0' FATAL 25-02 10:03:40,368 (PersistenceXmlLoader.java:parsePersistenceUnit:101) -test JTA javax.persistence.PersistenceException: java.lang.NullPointerException javax.persistence.PersistenceException: java.lang.NullPointerException at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:173) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:103) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27) at com.osc.proto.Activator.start(Activator.java:36) at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:994) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:988) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:969) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:314) at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:256) at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.preFindLocalClass(EclipseLazyStarter.java:83) at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:402) at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:186) at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:338) at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:390) at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:351) at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:81) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:276) at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:227) at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1245) at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:138) at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:759) at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243) at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:51) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:95) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:374) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:169) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.eclipse.core.launcher.Main.invokeFramework(Main.java:338) at org.eclipse.core.launcher.Main.basicRun(Main.java:282) at org.eclipse.core.launcher.Main.run(Main.java:977) at org.eclipse.core.launcher.Main.main(Main.java:952) Caused by: java.lang.NullPointerException at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:68) at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:139) ... 38 more I tried following the simple tutorial bundled with the EJB 3.0 embedded download, and not create an entity manager factory, but when I tried to persist my entity bean with the EntityManager, I got a null pointer exception when calling manager.persist(user). I poked around and found a section in the hibernate docs that says you have to call createEntityManagerFactory() to bootstrap the entity manager. I added that call and that's where I get an exception. 1. When using the EJB 3.0 embedded code, do I really have to call createEntitymanagerFactory()? Why doesn't the tutorial code do this? 2. Why am I getting an exception when I call createEntityManagerFactory()? Bryan View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3926283#3926283 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3926283 ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user