logo       

Re: simple Entity create() fails: msg#00046

java.geronimo.user

Subject: Re: simple Entity create() fails

Well, the error is coming up in our transaction code, and at a
glance, your ejb-jar.xml does not have any container transaction settings.
I wonder if we're expecting you to have a live transaction while you do
the entity create? Can you try adding a container transaction block
setting REQUIRED for all the methods of that entity, or else put a
UserTransaction around the code that calls it in the servlet?

Aaron

On Fri, 15 Jul 2005, marquis wrote:
> Hello,
> I have a very simple Entity bean which runs fine on openejb 0.9.2 but
> fails on geronimo (co lately.)
> (Code -- very simple -- at the end of this mail).
> I made it BMP (removing all database-related stuff) to simplify things and
> try to isolate the problem.
>
> ---This is the ejb-jar, very simple:
> <?xml version="1.0"?>
>
> <ejb-jar
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
> version="2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns="http://java.sun.com/xml/ns/j2ee";>
>
> <description>sample Application</description>
> <display-name>EJB</display-name>
> <enterprise-beans>
> <entity>
> <ejb-name>Employee</ejb-name>
> <home>acm.EmployeeHome</home>
> <remote>acm.Employee</remote>
> <ejb-class>acm.EmployeeBean</ejb-class>
> <persistence-type>Bean</persistence-type>
> <prim-key-class>java.lang.Integer</prim-key-class>
> <reentrant>false</reentrant>
> </entity>
> </enterprise-beans>
> </ejb-jar>
>
> --- and the openejb-jar.xml (not needed I think) :
> <?xml version="1.0"?>
>
> <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar";
> configId="org/openejb/itests"
> parentId="org/apache/geronimo/Server"
> xmlns:naming="http://geronimo.apache.org/xml/ns/naming";
> >
> <enterprise-beans>
> <entity>
> <ejb-name>Employee</ejb-name>
> <jndi-name>Employee</jndi-name>
> </entity>
> </enterprise-beans>
> </openejb-jar>
>
> The bean is called by a servlet in its doPost() (the bean is declared in
> web-xml and geronimo-web.xm) :
> ...
> try {
> Object ref3 =
> jndiContext.lookup("java:comp/env/ejb/Employee");
> eh= (EmployeeHome) PortableRemoteObject.narrow(ref3,
> EmployeeHome.class);
> } catch(Exception e) {
> throw new ServletException("Failed to lookup employee", e);
> }
>
> Employee employee = null;
> try {
> employee = eh.create("jack", "a", "ja@xxxxx");
> } catch (Exception e) { throw new ServletException("create()
> failed",
> e); } // <-- THROWN !!!
>
> if (employee != null) out.println("first name is: "
> + employee.getFirstname() + "<br>");
> //employee.remove();
> }
> ...
>
> The Home is found but it cannot create() the remote interface, as
> the marked exception is thrown and following stack produced:
>
>
>
> 10:16:10,380 WARN [SystemExceptionInterceptor] Employee
> java.lang.NullPointerException
> at
> org.apache.geronimo.transaction.DoubleKeyedHashMap$Key.hashCode(DoubleKeyedHashMap.java:66)
> at java.util.HashMap.hash(HashMap.java:261)
> at java.util.HashMap.put(HashMap.java:379)
> at
> org.apache.geronimo.transaction.DoubleKeyedHashMap.put(DoubleKeyedHashMap.java:33)
> at
> org.apache.geronimo.transaction.context.AbstractTransactionContext.associate(AbstractTransactionContext.java:46)
> at
> org.openejb.entity.bmp.BMPCreateMethod.execute(BMPCreateMethod.java:138)
> at
> org.openejb.dispatch.DispatchInterceptor.invoke(DispatchInterceptor.java:72)
> at
> org.apache.geronimo.naming.java.ComponentContextInterceptor.invoke(ComponentContextInterceptor.java:56)
> at
> org.openejb.ConnectionTrackingInterceptor.invoke(ConnectionTrackingInterceptor.java:81)
> at
> org.openejb.entity.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:136)
> at
> org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:140)
> at
> org.openejb.transaction.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:80)
> at
> org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor.java:82)
> at
> org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:234)
> at
> org.openejb.proxy.EJBMethodInterceptor.intercept(EJBMethodInterceptor.java:129)
> at
> org.openejb.proxy.EntityEJBHome$$EnhancerByCGLIB$$e5e300df.create(<generated>)
> at
> org.jboss.docs.interest.InterestServlet.doPost(InterestServlet.java:132)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:615)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
> at
> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> at
> org.apache.geronimo.jetty.JettyServletHolder.handle(JettyServletHolder.java:92)
> at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:832)
> at
> org.mortbay.jetty.servlet.JSR154Filter.doFilter(JSR154Filter.java:171)
> at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:823)
> at
> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:473)
> at
> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)
> at org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> at
> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:623)
> at org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> at org.mortbay.http.HttpConnection.service(HttpConnection.java:814)
> at
> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:981)
> at org.mortbay.http.HttpConnection.handle(HttpConnection.java:831)
> at
> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
> javax.servlet.ServletException: create() failed
> at
> org.jboss.docs.interest.InterestServlet.doPost(InterestServlet.java:133)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:615)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
> at
> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> at
> org.apache.geronimo.jetty.JettyServletHolder.handle(JettyServletHolder.java:92)
> at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:832)
> at
> org.mortbay.jetty.servlet.JSR154Filter.doFilter(JSR154Filter.java:171)
> at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:823)
> at
> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:473)
> at
> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)
> at org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> at
> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:623)
> at org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> at org.mortbay.http.HttpConnection.service(HttpConnection.java:814)
> at
> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:981)
> at org.mortbay.http.HttpConnection.handle(HttpConnection.java:831)
> at
> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
>
>
> I tried to make all this so simple as possible but cannot have it running.
> Any idea?
>
> Sam
>
>
>
> ---------------------------------
> code (very simple example from somewhere) :
>
>
> ---remote:---
> package acm;
>
> import javax.ejb.EJBObject;
> import java.rmi.RemoteException;
>
> public interface Employee extends EJBObject
> {
> public void says( String message )
> throws RemoteException;
>
> public void setAge(int age) throws RemoteException;
> public String getFirstname() throws RemoteException;
>
> public void add(int i) throws RemoteException;
> public int getTotal() throws RemoteException;
> }
> ---bean:---
> package acm;
>
> import javax.ejb.*;
> import java.rmi.RemoteException;
>
> public class EmployeeBean implements EntityBean
> {
> public int id;
> public String firstname;
> public String lastname;
> public String email;
> public int age;
> public int total;
>
> public int getId() { return id; }
> public void setId(int id) { this.id = id; }
>
> public String getFirstname() { return firstname; }
> public void setFirstname(String a) { firstname = a; }
>
> public String getLastname() { return lastname; }
> public void setLastname(String a) { lastname = a; }
>
> public String getEmail() { return email; }
> public void setEmail(String a) { email = a; }
>
> public int getAge() { return age; }
> public void setAge(int age) { this.age = age; }
>
> public int getTotal() { return total; }
> public void setTotal(int i) { total = i; }
>
> public EntityContext context;
>
> public EmployeeBean()
> {
> }
>
> public Integer ejbCreate( String firstname, String lastname, String
> email )
> throws CreateException
> {
> this.firstname = firstname;
> this.lastname = lastname;
> this.email = email;
> return null;
> }
> public void ejbPostCreate( String firstname, String lastname, String
> email )
> throws CreateException
> {
> }
>
>
> public Integer ejbCreate( String firstname, String lastname, String
> email, int age )
> throws CreateException
> {
> this.firstname = firstname;
> this.lastname = lastname;
> this.email = email;
> this.age = age;
> return null;
> }
> public void ejbPostCreate( String firstname, String lastname, String
> email, int age )
> throws CreateException
> {
> }
>
>
>
> public void says( String message )
> {
> System.out.println( "[" + firstname + " " + lastname +
> "(" + id + ") " + email + "] " + message );
> }
>
> public void add(int i) {
> total += i;
> }
>
> public void setEntityContext( EntityContext context )
> throws EJBException, RemoteException
> {
> this.context = context;
> }
>
> public void unsetEntityContext()
> throws EJBException, RemoteException
> {
> }
>
> public void ejbActivate()
> throws EJBException, RemoteException
> {
> }
>
> public void ejbLoad()
> throws EJBException, RemoteException
> {
> }
>
> public void ejbPassivate()
> throws EJBException, RemoteException
> {
> }
>
> public void ejbRemove()
> throws RemoveException, EJBException, RemoteException
> {
> }
>
> public void ejbStore()
> throws EJBException, RemoteException
> {
> }
> }
> ---home:---
> package acm;
>
> import javax.ejb.CreateException;
> import javax.ejb.EJBHome;
> import javax.ejb.FinderException;
> import java.rmi.RemoteException;
>
> public interface EmployeeHome extends EJBHome
> {
> public Employee create( String firstname, String lastname, String email )
> throws RemoteException, CreateException;
>
> public Employee create( String firstname, String lastname, String email,
> int age )
> throws RemoteException, CreateException;
>
> public Employee findByPrimaryKey( Integer id )
> throws RemoteException, FinderException;
> }
>
>
>



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise