Problems on the persistence of a CMP Entity Bean

Discussions

EJB programming & troubleshooting: Problems on the persistence of a CMP Entity Bean

  1. Problems on the persistence of a CMP Entity Bean (4 messages)

    Hello everyone! I have a peculiar problem and I hope somebody can help me on this.
    I have a client that as to fill the database of the "Producer" Entity (a CMP Entity bean), for example:

    for (int i = 1; i< 5; i++)
    {
    ProducerValue value = new ProducerValue("test " + i);
    ProducerEntity[] prodEnts = (ProducerEntity[]) producerEntityHome.findAllProducers().toArray();
    for (int i = 0; i < prodEnts.length; i++)
    {
    if (value.getName().equals(prodEnts[i].getName()))
    {
    throw new DuplicateKeyException("Name already exists");
    }
    }
    producerEntityHome.create(value);
    }


     but the odd thing is that it creates the 2 first producers, and everything else returns an exception
     
    "javax.ejb.NoSuchEntityException: Entity not found"

     and on the server side:

    NoSuchEntityException: javax.ejb.NoSuchEntityException: Entity not found: Test 1
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:215)
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:83)
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadEntity(JDBCStoreManager.java:632)
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadEntity(JDBCStoreManager.java:614)
    at org.jboss.ejb.plugins.CMPPersistenceManager.loadEntity(CMPPersistenceManager.java:386)
    at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.loadEntity(CachedConnectionInterceptor.java:353)
    at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:232)
    at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
    at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:82)
    at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:174)
    at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:89)
    at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:53)
    at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
    at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:216)
    at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
    at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
    at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
    at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
    at org.jboss.ejb.EntityContainer.internalInvoke(EntityContainer.java:483)
    at org.jboss.ejb.Container.invoke(Container.java:674)
    at sun.reflect.GeneratedMethodAccessor92.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
    at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:101)
    at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:83)
    at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
    at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
    at org.jboss.proxy.ejb.EntityInterceptor.invoke(EntityInterceptor.java:97)
    at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
    at $Proxy271.getName(Unknown Source)
    at producer.JVTProducerSessionBean.createProducerByValue(JVTProducerSessionBean.java:95)
    at producer.JVTProducerSessionBean.tryCreateProducersByValues(JVTProducerSessionBean.java:1038)
    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 org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:629)
    at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
    at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
    at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
    at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
    at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
    at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
    at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
    at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
    at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:322)
    at org.jboss.ejb.Container.invoke(Container.java:674)
    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 org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
    at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
    at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)


    Here is a scratch of the bean:
    By the way I'm using Eclipse 2.1, Lomboz 2.1.1 and JBoss 3.2.1

    /**
     * @ejb.bean name="ProducerEntity"
     * jndi-name="ProducerEntityBean"
     * type="CMP"
     * primkey-field="producerKey"
     * schema="producerSchema"
     * cmp-version="2.x"
     * reentrant="true"
     *
     * @jboss.unknown-pk class="common.ManagedEntityKey"
     * column-name="producerKey"
     * sql-type="BLOB"
     *
     * @ejb.persistence
     * table-name="producerTable"
     *
     * @jboss.persistence
     * table-name="producerTable"
     * create-table="true"
     * remove-table="true"
     *
     * @ejb.finder
     * query="SELECT OBJECT(a) FROM producerSchema as a"
     * signature="java.util.Collection findAllProducers()"
     *
     * @ejb.transaction type="NotSupported"
     *
     **/
    public abstract class ProducerEntityBean implements EntityBean
    {
    private EntityContext ctx;

    ...

    /**
    * @ejb.create-method
    */
    public common.ManagedEntityKey ejbCreate(ProducerValue producerValue) throws CreateException
    {
    setProducerKey(producerValue.getKey());

    ...

    return null;
    }
    public void ejbPostCreate(ProducerValue producerValue) throws CreateException
    {
    return;
    }
    public void setEntityContext(EntityContext ctx)
    {
    this.ctx = ctx;
    }
    public void unsetEntityContext()
    {
    this.ctx = null;
    }
    /**
    * @ejb.persistence
    * column-name="producerKey"
    * sql-type = "BLOB"
    * @ejb.pk-field
    *
    * @jboss.persistence
    * @jboss.column-name name="producerKey"
    * @jboss.sql-type type="BLOB"
    *
    * @ejb.interface-method
    */
    public abstract common.ManagedEntityKey getProducerKey();
    public abstract void setProducerKey(common.ManagedEntityKey producerKey);

    ...

    }

    I'm wondering if I have to define the ejbActivate() and ejbPassivate() some how...
  2. You're not show the client-side exception point, but I'll assume it is at the findAllProducers() invocation.

    I would first suspect the implementation of your key class, common.ManagedEntityKey, which you do not show. Give that a sniff, or post it here.

    -Peris
  3. Here is the draft of the ManagedEntityKey as requested:

    package common;
    import java.io.Serializable;
    public class ManagedEntityKey implements Cloneable, Serializable
    {
    private String name;

    ...

    public ManagedEntityKey(String name)
    {
    this.name = name;

    ...

    }
    public Object clone()
    {
    ManagedEntityKey clone = null;
    try
    {
    clone = (ManagedEntityKey) super.clone();
    clone.name = new String(name);

    ...

    }
    catch (Exception e)
    {
    clone = null;
    }
    return clone;
    }
    public boolean equals(Object other)
    {
    if (other == this)
    {
    return true;
    }
    if (!(other instanceof ManagedEntityKey))
    {
    return false;
    }
    ManagedEntityKey otherKey = (ManagedEntityKey) other;
    if (hashCode() == otherKey.hashCode())
    {
    if (!name.equals(otherKey.name))
    {
    return false;
    }

    ...

    }
    else
    {
    return false;
    }
    return true;
    }

    ...

    public String getName()
    {
    return new String(name);
    }
    public int hashCode()
    {
    return name.hashCode();
    }
    public String toString()
    {
    return ("Key|PrimaryKey: " + getName());
    }
    }


    The exception that occurs in the client side is:

    java.rmi.NoSuchObjectException: Entity not found: primaryKey=Key|PrimaryKey: Test 1; nested exception is:
    javax.ejb.NoSuchEntityException: Entity not found: primaryKey=Key|PrimaryKey: Test 1
  4. I forgot to mention but the exception occurs at the getName().

    I've run some tests and the findAllProducers() seems to be working fine because the size of the Collection that returns, for each cycle, is correct:

    The first time is 0...
    The second time is 1 and the getName() returns "Test 1"...
    The third time is 2 (supposedly it has "Test 1" and "Test 2") but the getName() now throws the exception above.
  5. Found solution yet[ Go to top ]

    Hi, Im experiencing a similar problem where I get a complaint abt the cmp primary when I try to use the getter methods on the object.did u find a solution?