• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

entity bean primary key error

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
my deployed bean responds with the following error (allthough the entity with 123 as primary key does exist in the database):

C:\stage\entity>java PersonClient
time for creating InitialContext in milli sec : 1162
time for JNDI lookup in milli sec : 140
Received an unexpected exception javax.ejb.ObjectNotFoundException: Bean with primary key '123' was not found by 'findBy
PrimaryKey'.
Start server side stack trace:
javax.ejb.ObjectNotFoundException: Bean with primary key '123' was not found by 'findByPrimaryKey'.
at PersonBean2_k3evwt__WebLogic_CMP_RDBMS.ejbFindByPrimaryKey(PersonBean2_k3evwt__WebLogic_CMP_RDBMS.java:453)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.findByPrimaryKey(RDBMSPersistenceManager.java:167)
at weblogic.ejb20.manager.BaseEntityManager.findByPrimaryKey(BaseEntityManager.java:430)
at weblogic.ejb20.manager.BaseEntityManager.remoteFindByPrimaryKey(BaseEntityManager.java:377)
at weblogic.ejb20.internal.EntityEJBHome.findByPrimaryKey(EntityEJBHome.java:332)
at PersonBean_k3evwt_HomeImpl.findByPrimaryKey(PersonBean_k3evwt_HomeImpl.java:138)
at PersonBean_k3evwt_HomeImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace
while using the PersonEJB.
Exception in thread "main" javax.ejb.ObjectNotFoundException: Bean with primary key '123' was not found by 'findByPrimar
yKey'.
Start server side stack trace:
javax.ejb.ObjectNotFoundException: Bean with primary key '123' was not found by 'findByPrimaryKey'.
at PersonBean2_k3evwt__WebLogic_CMP_RDBMS.ejbFindByPrimaryKey(PersonBean2_k3evwt__WebLogic_CMP_RDBMS.java:453)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.findByPrimaryKey(RDBMSPersistenceManager.java:167)
at weblogic.ejb20.manager.BaseEntityManager.findByPrimaryKey(BaseEntityManager.java:430)
at weblogic.ejb20.manager.BaseEntityManager.remoteFindByPrimaryKey(BaseEntityManager.java:377)
at weblogic.ejb20.internal.EntityEJBHome.findByPrimaryKey(EntityEJBHome.java:332)
at PersonBean_k3evwt_HomeImpl.findByPrimaryKey(PersonBean_k3evwt_HomeImpl.java:138)
at PersonBean_k3evwt_HomeImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace
at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:85)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:262)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:229)
at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)
at $Proxy1.findByPrimaryKey(Unknown Source)
at PersonClient.runClient(PersonClient.java:82)
at PersonClient.main(PersonClient.java:110)
C:\stage\entity>
****************************************
My bean code looks like:

import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
public abstract class PersonBean implements EntityBean {
String svnr;
String name;
// CREATION METHODS
public String ejbCreate(String id) {
setId(id);
return null;
}
public void ejbPostCreate(String id) {
}
public String ejbCreate(String id, String n) {
setId(id);
setName(n);
return null;
}
public void ejbPostCreate(String id, String name) {
}
public abstract String getId();
public abstract void setId(String n);
public abstract String getName();
public abstract void setName(String n);
// CALLBACK METHODS
public void setEntityContext(EntityContext cntx) {
}
public void unsetEntityContext() {
}

public void ejbLoad() {
}
public void ejbStore() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void ejbRemove() {
}
}

**********************************
The ejb-jar.xml:
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

<!-- Generated XML! -->
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>PersonBean2</ejb-name>
<home>PersonHome</home>
<remote>Person</remote>
<ejb-class>PersonBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<abstract-schema-name>PersonBean2</abstract-schema-name>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<cmp-field>
<field-name>id</field-name>
</cmp-field>
<primkey-field>name</primkey-field>
<query>
<query-method>
<method-name>findByName</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql><![CDATA[SELECT OBJECT(o) FROM PersonBean2 AS o]]></ejb-ql>
</query>
</entity>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>PersonBean2</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem is in the ejb-jar.xml:
<primkey-field>name</primkey-field>
I am assuming that you do not want the name field as your primary key. Therefore it should be:
 
Maximilian Trenks
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
many, many thanx.
you have the eye of an eagle.
i looked over it several times and did not find it.
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic