Entity bean with primary key generated by trigger
Hi,
We have a table(oracle) with one column as primary key,
but the primary key is generated by trigger every time
a new row is inserted into this table, inside the trigger,
it uses oracle sequence to get the next val.
If we want to use entity bean with it, what should we specify, it's not application-managed primay key, it's
not auto-generated primary key either. How can we resolve
it without change the database part.
Any thought is appreciated.
Thanks
afang
The code is already there with JDBC call inserting
into the table, the inserting trigger then will generate
sequence key and being inserted into primary key column.
Now wondering if it's possible to change the code to use entity bean but without modifying the trigger (since it contains other business logics).
Similar Messages
-
Entity Bean with Primary Key Class
Hi
I am trying to develop an entity bean attached to a key which have a
composite key using Primary Key Class. When I use the findByPrimaryKey
method of the bean it throws an exception as follows,
java.sql.SQLException: Parameter typecheck failed: invalid parameter type:
ORA-00000: normal, successful completion
at com.netscape.server.jdbc.PreparedStatement.verifyError(Unknown Source)
at com.netscape.server.jdbc.PreparedStatement.afterVerify(Unknown Source)
at com.netscape.server.jdbc.PreparedStatement.executeQuery(Unknown Source)
at com.netscape.server.ejb.SQLPersistenceManager.find(Unknown Source)
at
com.netscape.server.ejb.EntityDelegateManagerImpl.doPersistentFind(Unknown
Source)
at com.netscape.server.ejb.EntityDelegateManagerImpl.find(Unknown Source)
at com.kivasoft.eb.EBHomeBase.findSingleByParms(Unknown Source)
at
TestBean2.ejb_home_TestBean2_EntityBean2Bean.findByPrimaryKey(ejb_home_TestB
ean2_EntityBean2Bean.java:120)
at
TestBean2.ejb_kcp_skel_EntityBean2Home.findByPrimaryKey__TestBean2_EntityBea
n2__TestBean2_TestBKey(ejb_kcp_skel_EntityBean2Home.java:258)
at com.kivasoft.ebfp.FPRequest.invokenative(Native Method)
at com.kivasoft.ebfp.FPRequest.invoke(Unknown Source)
at
TestBean2.ejb_kcp_stub_EntityBean2Home.findByPrimaryKey(ejb_kcp_stub_EntityB
ean2Home.java:341)
at
TestBean2.ejb_stub_EntityBean2Home.findByPrimaryKey(ejb_stub_EntityBean2Home
..java:88)
at TestBean2.Simple1.defaultAction(Simple1.java:115)
at TestBean2.Simple1.doGet(Simple1.java:26)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
Source)
at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unknown
Source)
at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at java.lang.Thread.run(Thread.java:479)
javax.ejb.FinderException
at com.netscape.server.ejb.SQLPersistenceManager.find(Unknown Source)
at
com.netscape.server.ejb.EntityDelegateManagerImpl.doPersistentFind(Unknown
Source)
at com.netscape.server.ejb.EntityDelegateManagerImpl.find(Unknown Source)
at com.kivasoft.eb.EBHomeBase.findSingleByParms(Unknown Source)
at
TestBean2.ejb_home_TestBean2_EntityBean2Bean.findByPrimaryKey(ejb_home_TestB
ean2_EntityBean2Bean.java:120)
at
TestBean2.ejb_kcp_skel_EntityBean2Home.findByPrimaryKey__TestBean2_EntityBea
n2__TestBean2_TestBKey(ejb_kcp_skel_EntityBean2Home.java:258)
at com.kivasoft.ebfp.FPRequest.invokenative(Native Method)
at com.kivasoft.ebfp.FPRequest.invoke(Unknown Source)
at
TestBean2.ejb_kcp_stub_EntityBean2Home.findByPrimaryKey(ejb_kcp_stub_EntityB
ean2Home.java:341)
at
TestBean2.ejb_stub_EntityBean2Home.findByPrimaryKey(ejb_stub_EntityBean2Home
..java:88)
at TestBean2.Simple1.defaultAction(Simple1.java:115)
at TestBean2.Simple1.doGet(Simple1.java:26)
[03/Aug/2001 15:26:41:7] error: Exception: SERVLET-execution_failed: Error
in executing servlet Simat
javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServletple1: java.lang.ClassCastException:
com.netscape.server.deployment.EntityBeanDescriptor
Exception .service(HttpServlet.java:865)
at com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
Source)
at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unknown
Source)Stack Trace:
java.lang.ClassCastException:
com.netscape.server.deployment.EntityBeanDescriptor
a
at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
at com.kivasoft.applogic.AppLogic.ext
com.netscape.server.servlet.servletrunner.AppInfo.popWebAppDescriptor(Unknow
n Source)
at com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
Source)
at com.netscape.server.seecute(Unknown Source)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at java.lang.Threadrvlet.servletrunner.ServletRunner.execute(Unknown
Source)
at com.kivasoft.applogic.AppLogic.execu.run(Thread.java:479)
te(Unknown Source)
at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at java.lang.Thread.run(Thread.java:479)
Any kind of help is appreciated. I am using iPlanet App Builder 6.0 with iAS
6.0 SP1.
Thanks
Bhaskara Murthy
Eclipse Networks Inc"Bhamu" <[email protected]> wrote in message
news:9keuo4$[email protected]..
I am trying to develop an entity bean attached to a key which have a
composite key using Primary Key Class. When I use the findByPrimaryKey
method of the bean it throws an exception as follows,I notice that you are using the reference CMP plugin.
at com.netscape.server.ejb.SQLPersistenceManager.find(Unknown Source)I'm also willing to bet that you may have created your own primary key class
with a single field, rather than using the fields type as a primitive
primary key class. If you do this, then SQLPersistenceManager will break.
It is badly written, and has some stupid assumptions. The one I remember
the most is that if you only have one primary key field, then
SQLPersistenceManager assumes you have used a primitive type such as
java.lang.String or java.lang.Integer, to represent it, rather than creating
your own <Enity>Pk.java file.
SQLPersistenceManager works for toy examples, but in general I would say it
is broken and unusable. Either use BMP, or splash out the money for Coco
Base from Thought Inc. Currently the only CMP plugin for iPlanet App server,
other than the reference implementation, that I know of. -
Deploying BMP Entity Bean with primary key calss
Hi,
I am using EJB 2.0 with and websphere studio 5.0 and database is sql server 2000.
My BMP Entity bean has a primary key class.From my client I am invoking the Entity Bean by calling it's findbyprimarykey method.
The home interface of my findbyprimarykey method returns a class of type Remote.But in the Entity Bean class,the return type is the primarykey class type.
My problem is invoking this findbyprimarykey from the client to get the remote interface so that the other business methods of the entity bean can be called.
The control goes into the ejbFindbyPrimaryKey but when it is returing from the Entity Bean class,it gives a remote exception (as the return type in Entity Bean class and Home interface are different for the findbyprimarykey method).
I think that somewhere in the deployment decriptor in my websphere,i have to specify the primarykey class type,which i am missing out and hence getting the error.
Please help me out with your advice and solution.
Thanks
Rahul PriyadarshiHi,
Sorry to disturb you again.
Even my code is also almost the same....i am pasting the code below...Please go through it and let me know if I have made any mistake..
EditVendorEntityBean.....(Bean Class)
package code.beans.EditVendor;
import code.beans.dataAccess.*;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.EJBException;
import javax.ejb.FinderException;
import javax.ejb.ObjectNotFoundException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.sql.*;
import javax.sql.*;
import java.util.*;
* Bean implementation class for Enterprise Bean: EditVendorEntity
public class EditVendorEntityBean implements javax.ejb.EntityBean {
private static Hashtable dataSources = new Hashtable();
private String username;
private int Vendor_ID;
private int Category_Id;
private String Category_Name;
private String Vendor_Name;
private String Vendor_Address1;
private String Vendor_Address2;
private String Contact_Name;
private String Home_Phone;
private String Work_Phone;
private String email;
private String faxno;
private String userloginname;
private boolean dirtyFlag = false;
private EntityContext context;
private static final String DS_NAME = "jdbc/spiPOPS";
Connection con = null;
Statement stmt = null;
PreparedStatement st = null;
ResultSet res = null;
//***********************Business Methods*********************
// Begin of Busines Methods
public void setData (String[] catname, String vendorname,String vendadd1,String vendadd2,String vendcontact,String venoff,String venres,String mailid,String venfax) {
System.out.println("in setData where Vendor Id= "+ Vendor_ID);
boolean status=false;
boolean existing=false;
ArrayList cat=new ArrayList();
try
cat=getcategorylist(this.Vendor_ID);
catch(SQLException e)
System.out.println("Could not get category list");
System.out.println("Size of cat array -->" + cat.size() + " and string array size -->" + catname.length);
if(catname.length>0)
//Removing unwanted vendor categories for a particular vendor id
for(int i=0;i<cat.size();i++)
existing=false;
String tempdata=(String)cat.get(i);
for(int j=0;j<catname.length;j++)
if(tempdata.equals(catname[j]))
existing=true;
if(!existing)
try
delvencat(this.Vendor_ID,tempdata.trim());
catch(SQLException e)
System.out.println("Could not delete record in POPS_VENDOR_CATEGORY for -->" + tempdata);
//Adding new vendor categories for a particular vendor
try
for(int i=0;i<catname.length;i++)
status=false;
String strcat=catname;
status=checkcat(this.Vendor_ID,strcat.trim());
if(!status)
insertvencat(this.Vendor_ID,strcat.trim());
catch(SQLException e)
System.out.println("Could not insert or select from POPS_VENDOR_CATEGORY table");
this.Vendor_Name =vendorname;
this.Vendor_Address1 =vendadd1;
this.Vendor_Address2 =vendadd2;
this.Contact_Name =vendcontact;
this.Work_Phone =venoff;
this.Home_Phone =venres;
this.email =mailid;
this.faxno =venfax;
dirtyFlag = true;
System.out.println("Leaving set data method");
public Vector getData() {
Vector vctRec=new Vector();
ArrayList arrdatas = new ArrayList();
arrdatas.add(""+this.Vendor_ID);
arrdatas.add(this.Vendor_Name);
arrdatas.add(this.Vendor_Address1);
arrdatas.add(this.Vendor_Address2);
arrdatas.add(this.Contact_Name);
arrdatas.add(this.Work_Phone);
arrdatas.add(this.Home_Phone);
arrdatas.add(this.email);
arrdatas.add(this.faxno);
vctRec.addElement(arrdatas);
ArrayList cat=new ArrayList();
try
System.out.println("Calling getcategorylist from getdata with vendorid-->" + this.Vendor_ID);
cat = getcategorylist(this.Vendor_ID);
catch(SQLException e)
System.out.println("Could not get datas for category list");
vctRec.addElement(cat);
ArrayList allcats=new ArrayList();
try
allcats = getallcategorylist();
catch(SQLException e)
System.out.println("Could not get datas for category list");
vctRec.addElement(allcats);
dirtyFlag = false;
System.out.println("Before return statement in getdata with vector size -->" + vctRec.size());
return vctRec;
// End of Business Methods
//**************************Entity Bean Methods*******************************
* ejbActivate
public void ejbActivate() {
Vendor_ID = Integer.parseInt((String)context.getPrimaryKey());
System.out.println("Inside ejbActivate Vendor_ID-->"+ Vendor_ID);
* ejbLoad
public void ejbLoad() {
System.out.println("Inside ejbLoad ********" );
try {
loadRow();
}catch (Exception ex) {
System.out.println("Failed in loadRow()");
throw new EJBException("ejbLoad: " +
ex.getMessage());
* ejbPassivate
public void ejbPassivate() {
System.out.println("Inside ejbPassivate " );
Vendor_ID = 0;
* ejbRemove
public void ejbRemove() throws javax.ejb.RemoveException {
//Empty Method
* ejbStore
public void ejbStore() {
System.out.println("Inside ejbStore " );
try {
storeRow();
}catch (Exception ex) {
System.out.println("Exception thrown in storeRow" + ex.getMessage());
throw new EJBException("ejbLoad: " +
ex.getMessage());
* getEntityContext
public javax.ejb.EntityContext getEntityContext() {
return context;
* setEntityContext
public void setEntityContext(javax.ejb.EntityContext ctx) {
System.out.println("Inside setEntityContext " );
try{
con = getConnection(DS_NAME);
System.out.println("DB Connection Created!!");
catch(Exception e){
this.context = ctx;
* unsetEntityContext
public void unsetEntityContext() {
System.out.println("Inside unsetEntityContext " );
closeDbConnection(con, res, st);
this.context = null;
* ejbCreate
//code.beans.EditVendor.EditVendorEntityKey
public code.beans.EditVendor.EditVendorEntityKey ejbCreate(String vendorid)
throws javax.ejb.CreateException {
return new EditVendorEntityKey(vendorid);
//return null;
* ejbPostCreate
public void ejbPostCreate(String vendorid) throws javax.ejb.CreateException {
//Empty
* ejbFindByPrimaryKey
//code.beans.EditVendor.EditVendorEntityKey
public code.beans.EditVendor.EditVendorEntityKey ejbFindByPrimaryKey(
code.beans.EditVendor.EditVendorEntityKey primaryKey)
throws javax.ejb.FinderException {
try {
if(selectByPrimaryKey(Integer.parseInt(primaryKey.getVendorId()))) {
System.out.println("Leaving the findbyprimarykey method from the entity bean");
return primaryKey;
//return null;
}else {
throw new ObjectNotFoundException
("Row for id " + primaryKey + " not found.");
}catch (Exception ex) {
throw new EJBException("EXCEPTION IN ejbFindByPrimaryKey :- " + ex.getMessage());
/*********************** Database Utility Routines *************************/
private boolean selectByPrimaryKey(int priKey)
throws SQLException {
System.out.println("inside selectByPrimaryKey for primary key " + priKey);
String queryStr ="SELECT VENDOR_ID FROM POPS_VENDOR WHERE VENDOR_ID = " + priKey;
System.out.println("in selectByPrimaryKey where queryString is: "+ queryStr);
stmt = con.createStatement();
ResultSet result = stmt.executeQuery(queryStr);
if(!result.next()) {
stmt.close();
System.out.println("Did not find "+priKey);
return false;
else { //Found the primaryKey
Vendor_ID = result.getInt("VENDOR_ID");
stmt.close();
return true;
private void loadRow() throws SQLException {
System.out.println("inside loadRow ...");
stmt = con.createStatement();
String queryStr = "SELECT VENDOR_NAME,VENDOR_ADDRESS1,VENDOR_ADDRESS2,CONTACT_NAME,HOME_PHONE,WORK_PHONE,EMAIL_ID,FAX_NO " +
"FROM POPS_VENDOR WHERE VENDOR_ID=" + Vendor_ID;
System.out.println("Inside loadRow()***********"+queryStr);
ResultSet result = stmt.executeQuery(queryStr);
ArrayList catadatas=new ArrayList();
if(!result.next())
throw new SQLException("No record for primary key" + Vendor_ID);
this.Vendor_ID =Vendor_ID;
this.Vendor_Name =result.getString("VENDOR_NAME");
this.Vendor_Address1 =result.getString("VENDOR_ADDRESS1");
this.Vendor_Address2 =result.getString("VENDOR_ADDRESS2");
this.Contact_Name =result.getString("CONTACT_NAME");
this.Home_Phone =result.getString("HOME_PHONE");
this.Work_Phone =result.getString("WORK_PHONE");
this.email =result.getString("EMAIL_ID");
this.faxno =result.getString("FAX_NO");
System.out.println("Leaving loadrow method with loaded datas for vendor -->" + Vendor_ID);
stmt.close();
private ArrayList getcategorylist(int vendor) throws SQLException{
String queryStr ="SELECT DISTINCT(VENDOR_CAT) FROM POPS_VENDOR_CATEGORY WHERE VENDOR_ID=" + vendor;
System.out.println("Query for the cat list --> " + queryStr);
stmt = con.createStatement();
ResultSet result = stmt.executeQuery(queryStr);
ArrayList catdatas=new ArrayList();
try{
while(result.next())
catdatas.add(result.getString("VENDOR_CAT"));
catch (SQLException e){
stmt.close();
System.out.println("Could not retrieve datas for Category list");
stmt.close();
System.out.println("size off array for cat -->" + catdatas.size() + " and datas ->" + catdatas);
return catdatas;
private ArrayList getallcategorylist() throws SQLException{
//String queryStr ="SELECT DISTINCT(VENDOR_CAT) FROM POPS_VENDOR_CATEGORY";
StringBuffer strquery=new StringBuffer(20);
strquery.append("SELECT DISTINCT(CATEGORY_NAME) FROM POPS_CATEGORY");
stmt = con.createStatement();
//ResultSet result = stmt.executeQuery(queryStr);
ResultSet result = stmt.executeQuery(strquery.toString());
ArrayList catdatas=new ArrayList();
try{
while(result.next())
//catdatas.add(result.getString("VENDOR_CAT"));
catdatas.add(result.getString("CATEGORY_NAME"));
catch (SQLException e){
stmt.close();
System.out.println("Could not retrieve datas for All Category list");
stmt.close();
return catdatas;
private void delvencat(int vendor,String vencat) throws SQLException {
int update=-1;
stmt = con.createStatement();
String queryStr ="DELETE FROM POPS_VENDOR_CATEGORY WHERE VENDOR_ID = " + vendor + " AND VENDOR_CAT = '" + vencat.toUpperCase() + "'";
System.out.println("Delete query --> " + queryStr);
update= stmt.executeUpdate(queryStr);
if(update!=1)
System.out.println("Did not find data to delete");
stmt.close();
private void insertvencat(int vendor,String vencat) throws SQLException {
int update=-1;
String queryStr ="INSERT INTO POPS_VENDOR_CATEGORY(VENDOR_ID,VENDOR_CAT)" +
" VALUES(" + vendor +",'" + vencat + "')";
System.out.println("Insert query --> " + queryStr);
stmt = con.createStatement();
update=stmt.executeUpdate(queryStr);
if(update!=1)
System.out.println("Could not insert records in the database");
stmt.close();
private boolean checkcat(int vendor,String catven) throws SQLException {
boolean datastatus=false;
String queryStr ="SELECT VENDOR_ID FROM POPS_VENDOR_CATEGORY WHERE VENDOR_ID = " + vendor + " AND VENDOR_CAT = '" + catven.toUpperCase() + "'";
stmt = con.createStatement();
ResultSet result = stmt.executeQuery(queryStr);
datastatus=result.next();
stmt.close();
return datastatus;
private void storeRow() throws SQLException {
System.out.println("Inside ejb store");
if (!dirtyFlag) {
System.out.println("Skipping the UPDATE because object is not dirty");
return;
CallableStatement cs=null;
try{
cs = con.prepareCall("EXEC POPS_VENDOR_UPDATE " + this.Vendor_ID + ",'" + this.Vendor_Name + "','" + this.Vendor_Address1 + "','" + this.Vendor_Address2 + "','" + this.Contact_Name + "','" + this.Work_Phone + "','" + this.Home_Phone + "','" + this.email + "','" + this.faxno +"'");
System.out.println("\n\n SQL Statement : \n " + "EXEC POPS_VENDOR_UPDATE " + this.Vendor_ID + ",'" + this.Vendor_Name + "','" + this.Vendor_Address1 + "','" + this.Vendor_Address2 + "','" + this.Contact_Name + "','" + this.Work_Phone + "','" + this.Home_Phone + "','" + this.email + "','" + this.faxno +"'");
cs.executeUpdate();
catch (SQLException e){
cs.close();
System.out. println("\n\n Error in calling stored procedure POPS_INSERT_NEW_REQUEST \n\n"+ e.getMessage() + "\n\n");
cs.close();
dirtyFlag = false;
private Connection getConnection(String dbName) throws SQLException
String configuredDataSourceName = null;
if (dbName == null) {
System.out.println("Attemp to get connection failed. The requested database name is null");
DataSource dbSource = getDataSource(dbName);
return dbSource.getConnection();
private DataSource getDataSource(String dbName)
// looking from cache;
DataSource dbSource = (DataSource) dataSources.get(dbName);
if (dbSource == null) { //we need to find it from JNDI
try {
Context ic = new InitialContext();
dbSource = (DataSource) ic.lookup(dbName);
dataSources.put(dbName, dbSource);
}catch (NamingException e){
return dbSource;
* User calls this function to safely close an connection
* @param connt The connection a datasource
* @param rs The resulSet inside this connection
* @param statement The statement associate with this connection
private void closeDbConnection(Connection cont,ResultSet rs,Statement statement)
if (rs != null)
try {
rs.close();
} catch (SQLException ignored) {
ignored.printStackTrace();
if (statement != null)
try {
statement.close();
} catch (SQLException ignored) {
ignored.printStackTrace();
if (cont != null)
try {
cont.close();
} catch (SQLException ignored) {
ignored.printStackTrace();
} //closeDbConnection
EditVendorEntity (Remote Interface)
package code.beans.EditVendor;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.util.*;
* Remote interface for Enterprise Bean: EditVendorEntity
public interface EditVendorEntity extends javax.ejb.EJBObject {
public void setData (String[] catname, String vendorname,String vendadd1,String vendadd2,String vendcontact,String venoff,String venres,String mailid,String venfax)
throws RemoteException;
public Vector getData() throws RemoteException;
EditVendorEntityHome (Home Interface)
package code.beans.EditVendor;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.DuplicateKeyException;
import javax.ejb.EJBHome;
import java.util.*;
* Home interface for Enterprise Bean: EditVendorEntity
public interface EditVendorEntityHome extends javax.ejb.EJBHome {
* Creates an instance from a key for Entity Bean: EditVendorEntity
public code.beans.EditVendor.EditVendorEntity create(String vendorid)
throws javax.ejb.CreateException, java.rmi.RemoteException;
* Finds an instance using a key for Entity Bean: EditVendorEntity
public code.beans.EditVendor.EditVendorEntity findByPrimaryKey(
code.beans.EditVendor.EditVendorEntityKey Vendor_ID)
throws javax.ejb.FinderException, java.rmi.RemoteException;
EditVendorEntityKey (Primary Key Class)
package code.beans.EditVendor;
* Key class for Entity Bean: EditVendorEntity
public class EditVendorEntityKey implements java.io.Serializable {
static final long serialVersionUID = 3206093459760846163L;
public String primkey;
* Creates an empty key for Entity Bean: EditVendorEntity
public EditVendorEntityKey() { }
public EditVendorEntityKey(String primarykey) {
this.primkey=primarykey;
public String getVendorId() {
return primkey;
* Returns true if both keys are equal.
public boolean equals(java.lang.Object otherKey) {
if (otherKey instanceof code.beans.EditVendor.EditVendorEntityKey) {
code.beans.EditVendor.EditVendorEntityKey o =
(code.beans.EditVendor.EditVendorEntityKey) otherKey;
return (primkey.equals(otherKey));
return false;
* Returns the hash code for the key.
public int hashCode() {
return (primkey.hashCode());
Please go through and give me your comments and solution...
Thanks in advance
Rahul -
CMP Entity Bean With Primary Key of int
Is it valid to have a CMP Entity Bean (v1.1) where the primary key is defined as the primitive 'int' instead of a true Java class?
Thanks in advance,
MarcHi,
Ur primary key in the EJB cant be a primitive data type. If the primary key in the table is a int,
then u will hv [bold] java.lang.Integer [bold] as the datatype in Entity Bean. If u hv further queries write me at [email protected]
Kesavan. -
WLS8.1sp4 running into Bean with primary key
We're facing an interesting issue with WLS8.1sp4.
We have upgraded from WLS6.1sp5 to WLS8.1sp4, while testing running into the following error.
javax.ejb.NoSuchObjectLocalException: [EJB:010140]Bean with primary key: '5375758' not found.: javax.ejb.NoSuchEntityException: [EJB:010140]Bean with primary key: '5375758' not found.
at weblogic.ejb20.manager.BaseEntityManager.checkForReentrant(BaseEntityManager.java:1460)
at weblogic.ejb20.manager.DBManager.preInvoke(DBManager.java:251)
at weblogic.ejb20.internal.BaseEJBLocalObject.preInvoke(BaseEJBLocalObject.java:228)
at weblogic.ejb20.internal.EntityEJBLocalObject.preInvoke(EntityEJBLocalObject.java:72)
at edu.harvard.gmas.budget.SegmentLineItemBean_uyzy57_ELOImpl.getSubagreement(SegmentLineItemBean_uyzy57_ELOImpl.java:138)
at edu.harvard.gmas.budget.SegmentCategoryManager.entityToSegmentLineItemData(SegmentCategoryManager.java:1610)
at edu.harvard.gmas.budget.SegmentCategoryManager.entityToSegmentCategoryData(SegmentCategoryManager.java:1494)
at edu.harvard.gmas.budget.SegmentCategoryManager.fetchSegmentCategoryData(SegmentCategoryManager.java:2833)
at edu.harvard.gmas.budget.CategoryBudgetManager.fetchCategoryBudgetDataForProposedBudget(CategoryBudgetManager.java:2882)
at edu.harvard.gmas.budget.BudgetMediatorBean.recalculateAndUpdateCategoryAmountsForProposedBudget(BudgetMediatorBean.java:6855)?:|?:|The code is already there with JDBC call inserting
into the table, the inserting trigger then will generate
sequence key and being inserted into primary key column.
Now wondering if it's possible to change the code to use entity bean but without modifying the trigger (since it contains other business logics). -
Javax.ejb.ObjectNotFoundException: Bean with primary key '555' was not foun
When I delete a particular entity bean instance, i get the following exception:
javax.ejb.ObjectNotFoundException: Bean with primary key '555' was not found by 'findByPrimaryKey'.
But, the instance is being deleted from the database.
Anyone please help,
Thank u,
SeshuGreetings,
When I delete a particular entity bean instance, i get
the following exception:
javax.ejb.ObjectNotFoundException: Bean with primary
key '555' was not found by 'findByPrimaryKey'.Interesting. How is your client calling the bean's remove method? Directly or through its home? Is it calling findByPrimaryKey before or after the call to remove? What is the PrimaryKey class type of your bean? Is the client passing a correct instance? All are things to be considered when troubleshooting your application. If more assistance is required, then seeing the relevant source code would be more helpful.
But, the instance is being deleted from the database.As is generally to be expected. No?
Anyone please help,
Thank u,
SeshuRegards,
Tony "Vee Schade" Cook -
Entity bean - Unknow primary key problem
Hi,
We are using entity bean with unknown primary key option to generate the primary key automatically. It works for all the tables except one table. What we observe is, auto generated primary key is less than the max value in the table and is clashing with one existing record. Any thoughts on what could be wrong?
Your help is highly appreciated.
Regards,
Chandra
Edited by: Chandrashekhar Singh on Mar 3, 2008 6:39 PMHi,
I think Vladimir's answer can help you.
[Entity bean - getting Duplicate Key Exception on ejbCreate;
Regards
Pavel -
Entity bean with another class as primary key generator class
Hi All,
I have a CMP entity bean in which I generate the primary key using my own class know as unique id generator.
I use it in ejbCreate method in the following manner
public Long ejbCreate(HospitalData hospitalData) throws CreateException{
Long myid = new Long(UniqueIdGenerator.getId());
System.out.println("My id generated ====== "+myid);
this.hospitalid = myid;
System.out.println("My id generated ====== "+this.hospitalid);
System.out.println("Came in ejbCreate method of HospitalEJB");
this.hospitalname = hospitalData.getHospitalname();
return null;
Can you tell me how I map this primary key in my ejb-jar.xml and jbosscmp-jdbc.xml.
Anyhelp would be appreciated.
Thanks
Sameer"Bhamu" <[email protected]> wrote in message
news:9keuo4$[email protected]..
I am trying to develop an entity bean attached to a key which have a
composite key using Primary Key Class. When I use the findByPrimaryKey
method of the bean it throws an exception as follows,I notice that you are using the reference CMP plugin.
at com.netscape.server.ejb.SQLPersistenceManager.find(Unknown Source)I'm also willing to bet that you may have created your own primary key class
with a single field, rather than using the fields type as a primitive
primary key class. If you do this, then SQLPersistenceManager will break.
It is badly written, and has some stupid assumptions. The one I remember
the most is that if you only have one primary key field, then
SQLPersistenceManager assumes you have used a primitive type such as
java.lang.String or java.lang.Integer, to represent it, rather than creating
your own <Enity>Pk.java file.
SQLPersistenceManager works for toy examples, but in general I would say it
is broken and unusable. Either use BMP, or splash out the money for Coco
Base from Thought Inc. Currently the only CMP plugin for iPlanet App server,
other than the reference implementation, that I know of. -
Creating entity beans with auto numbered primary key
I have two entity bean with a CMR between them. I am successfully creating the first one but when I try and create the child entity bean I get a NullPointerException.
Now I think this is because the gernerated code tries to get the primary key of the created entity bean and this is not set as it is set using a auto number in the database (An oracle sequence and trigger).
Is there anyway i can get round this problem?
Thanks in advance,
AdrianThis is the auto generated code:
public dmd.sync.ejbs.entity.AppliancePackInfoLocal create_Local(dmd.sync.dataobjects.dto.AppliancePackInfoDTO appliancePackInfoDTO, dmd.sync.ejbs.entity.AmppLocal amppLocal) throws javax.ejb.CreateException, java.rmi.RemoteException {
BeanO beanO = null;
dmd.sync.ejbs.entity.AppliancePackInfoLocal result = null;
boolean createFailed = false;
boolean preCreateFlag = false;
try {
beanO = super.createBeanO();
dmd.sync.ejbs.entity.AppliancePackInfoBean bean = (dmd.sync.ejbs.entity.AppliancePackInfoBean) beanO.getEnterpriseBean();
preCreateFlag = super.preEjbCreate(beanO);
bean.ejbCreate(appliancePackInfoDTO, amppLocal);
Object ejsKey = keyFromBean(bean);
result = (dmd.sync.ejbs.entity.AppliancePackInfoLocal) super.postCreate_Local(beanO, ejsKey, true);
bean.ejbPostCreate(appliancePackInfoDTO, amppLocal);
super.afterPostCreate(beanO, ejsKey);
It must be falling over on the last line as it calls the ejbPostCreate fine. -
Error While Deploying A CMP Entity Bean With A Composite Primary Key
Hello all,
I have a problem deploying CMP Entity beans with composite primary keys. I have a CMP Entity Bean, which contains a composite primary key composed of two local stubs. If you know more about this please respond to my post on the EJB forum (subject: CMP Bean Local Stub as a Field of a Primary Key Class).
In the mean time, can you please tell me what following error message means and how to resolve it? From what I understand it might be a problem with Sun ONE AS 7, but I would like to make sure it's not me doing something wrong.
[05/Jan/2005:12:49:03] WARNING ( 1896): Validation error in bean CustomerSubscription: The type of non-static field customer of the key class
test.subscription.CustomerSubscriptionCMP_1530383317_JDOState$Oid must be primitive or must implement java.io.Serializable.
Update the type of the key class field.
Warning: All primary key columns in primary table CustomerSubscription of the bean corresponding to the generated class test.subscription.CustomerSubscriptionCMP_1530383317_JDOState must be mapped to key fields.
Map the following primary key columns to key fields: CustomerSubscription.CustomerEmail,CustomerSubscription.SubscriptionType. If you already have fields mapped to these columns, verify that they are key fields.Is it enough that a primary key class be serializable or all fields have to implement Serializable or be a primitive?
Please let me know if you need more information to answer my question.
Thanks.
NikolaHi Nikola,
There are several problems with your CMP bean.
1. Fields of a Primary Key Class must be a subset of CMP fields, so yes, they must be either a primitive or a Serializable type.
2. Sun Application Server does not support Primary Key fields of an arbitrary Serializable type (i.e. those that will be stored
as BLOB in the database), but only primitives, Java wrappers, String, and Date/Time types.
Do you try to use stubs instead of relationships or for some other reason?
If it's the former - look at the CMR fields.
If it's the latter, I suggest to store these fields as regular CMP fields and use some other value as the PK. If you prefer that
the CMP container generates the PK values, use the Unknown
PrimaryKey feature.
Regards,
-marina -
Do I need to Create Primary Key Class for Entity beans with Local interface
Do I need to Create Primary Key Class for Entity beans with Local interface?
I have created my entity bean with the wizard in Sun One Studio and it does not create a primary key class for you.
I thought that the primary key class was required. My key is made up of only one field.
Anyone know the answer.
Jimu dont need to create a primary key class for a entity bean.if ur table's primary key feild(int ,float) is a built in or primitive data type,then u dont need one.But if ur table has a primary key field which is non primitive (for example StudentID,ItemID etc)then u have to create a primary key class.
hope this helps :-) -
Did elationship fields in entity bean with CMP same as foreign key in table
did elationship fields in entity bean with CMP same as foreign key in table database.so we don't have to make some foreign key column in table database.
did Container handle that both.
I need some answer
thank'sSuppose you have Group and user entity. Relation is 1-m. One group many users. When you create user, you dont need to send group id, All you need is create user and add it in collection (cmr-field) in group(user belongs to). Container will add its group id in user entity as well as in db.
-
Error on commit: Another user has changed the row with primary key : Rec_10
i am using jdev 11g R2
i implemented a master form and two detail tables on a jspx page
added createInsert, commit and rollback buttons
actions from these buttons all are executed from a bean
for entity attributes: refresh after insert and update are marked as checked
i am using login page for authorizing the user by getting the user information from user table
and then using the userid i am applying the setVisible property on some components at bean code
when i am inserting a new row there is no problem, here i am generating the new id like 'Rec_10', using a database sequence
but when i am trying to update a current record, it is showing the error --> Error on commit: JBO-25014: Another user has changed the row with primary key oracle.jbo.Key[Rec_22 ]
on clicking the commit button and also it is not updating the record on database
Thanx in Advance
kumar
Edited by: user10922309 on Nov 18, 2009 3:25 AM
Edited by: user10922309 on Nov 18, 2009 4:28 AMHi John
thnq for your quick responce.
here are the attribute details:
Attribute Name: RecID, Type: String, Value Type: Expression, Value: 'Rec_' + (new oracle.jbo.server.SequenceImpl("Rec_SEQ_AN", object.getDBTransaction())).getSequenceNumber()
Updatable: While New and Primary Key, Queryable, Persistent, Mandatory, Refresh After: Update, Refresh After: Update and Insert are markded as checked
error details:
oracle.jbo.RowInconsistentException: JBO-25014: Another user has changed the row with primary key oracle.jbo.Key[APP_22 ].
at oracle.jbo.server.OracleSQLBuilderImpl.doEntitySelectForAltKey(OracleSQLBuilderImpl.java:1062)
at oracle.jbo.server.BaseSQLBuilderImpl.doEntitySelect(BaseSQLBuilderImpl.java:548)
at oracle.jbo.server.EntityImpl.doSelect(EntityImpl.java:7762)
at oracle.jbo.server.EntityImpl.lock(EntityImpl.java:5554)
at oracle.jbo.server.EntityImpl.beforePost(EntityImpl.java:6057)
at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:6229)
at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3127)
at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:2935)
at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:1991)
at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2233)
at oracle.adf.model.bc4j.DCJboDataControl.commitTransaction(DCJboDataControl.java:1580)
at oracle.adf.model.binding.DCDataControl.callCommitTransaction(DCDataControl.java:1404)
at oracle.jbo.uicli.binding.JUCtrlActionBinding.doIt(JUCtrlActionBinding.java:1289)
at oracle.adf.model.binding.DCDataControl.invokeOperation(DCDataControl.java:2120)
at oracle.jbo.uicli.binding.JUCtrlActionBinding.invoke(JUCtrlActionBinding.java:693)
at oracle.adf.controller.v2.lifecycle.PageLifecycleImpl.executeEvent(PageLifecycleImpl.java:394)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding._execute(FacesCtrlActionBinding.java:217)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding.execute(FacesCtrlActionBinding.java:201)
--> at Index.saveApplicationAll(Index.java:6246)
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:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:157)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
at org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:53)
at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcastToMethodBinding(UIXComponentBase.java:1245)
at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:183)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:673)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:273)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:165)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:191)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:85)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:54)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:247)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:157)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.wls.JpsWlsFilter$1.run(JpsWlsFilter.java:96)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
at oracle.security.jps.wls.util.JpsWlsUtil.runJaasMode(JpsWlsUtil.java:146)
at oracle.security.jps.wls.JpsWlsFilter.doFilter(JpsWlsFilter.java:140)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:70)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:202)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3588)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2200)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2106)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1428)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
--> on click commit button Index.saveApplicationAll method will invoked.
Thats it.
Kumar
Edited by: user10922309 on Nov 18, 2009 4:32 AM -
Multiple users accessing entity bean with same PK
Hi,
Some body please clarify the below issue.
(EJB 1.1, WAS3.5)
I have two app servers and two clones each clone is running in each app server.
Stateful session bean access Entity beans to update/read record in the database.
According to my requirement multiple users can access the same entity data (same primary key). Suppose user A created a Stateful session bean SB1 and the SB1 created Entity1 with PK1, this is happening at clone1.
User B accessed the site and the request went to Clone2 and a new SB2 created, but the SB2 need to access the database with Same PK1.
For the above situation, I guess container can not create a new Entity bean with PK1 because EB with PK1 is already there and it tries to allocate same EB1 with SB2, so if two requests are concurrent do the SB2 wait to get the handle of the EB1?
Is there any way to create two Entity beans with same Primary Key at the same time but in different clone?
Thanks,
SagarHi,
The concurrency level has to be set at the level of database and the database will take care of consistency & integrity of the data. So specity the concurrency level on the database connection in each appserver. -
CMP Entity Bean with ejb-ql finder methods and INFORMIX database
Hi,
I have some CMP Entity Beans with finder methods defined in ejb-ql. In my ejb-jar, within <entity> definitions I have something like:
<entity>
<abstract-schema-name>BeanName</abstract-schema-name>
<cmp-field><field-name>fieldOne</field-name></cmp-field>
<cmp-field><field-name>fieldTwo</field-name></cmp-field>
<query>
<query-method>
<method-name>findAll</method-name>
<method-params></method-params>
</query-method>
<ejb-ql>SELECT OBJECT(o) FROM BeanName o</ejb-ql>
</query>
<entity>
And in persistent.xml:
<db-properties>
<data-source-name>datasource_name</data-source-name>
</db-properties>
<entity-bean>
<ejb-name>BeanName</ejb-name>
<table-name>table_name</table-name>
<field-map key-type="NoKey">
<field-name>fieldOne</field-name>
<column><column-name>column_one</column-name></column>
</field-map>
<field-map key-type="NoKey">
<field-name>fieldTwo</field-name>
<column><column-name>column_two</column-name></column>
</field-map>
<finder-descriptor>
<method-name>findAll</method-name>
<method-params/>
</finder-descriptor>
Once deployed, on server side, I can found a java source file (with corresponding compiled class file) in path:
j2ee/cluster/server0/apps/companyName/MyEARApp/EJBContainer/temp/temp38837373733/route/to/package/
with names:
BeanName0_0pm.java
BeanName0_0PM.class
and the generated java file contains this code:
public java.util.Enumeration ejbFindAll() throws javax.ejb.FinderException, javax.ejb.EJBException {
TransactionContext tc = pm.getTransactionContext();
Connection conn = null;
PreparedStatement pSt = null;
ResultSet ejb_rs = null;
int status = javax.transaction.xa.XAResource.TMSUCCESS;
try {
conn = pm.getConnectionForFindMethod();
pSt = conn.prepareStatement("SELECT \"O\".\"COLUMN_ONE\",\"O\".\"COLUMN_TWO\", FROM \"TABLE_NAME\" \"O\"");
ejb_rs = pSt.executeQuery();
I'm trying to call this method but it throws a SQLException when preparing the statement.
It seems that Informix does not like this SQL syntax because of upper case names, doble quotes on table alias, or something else.
When editing persistent.xml in netweaver, I can define the element <datasource-vendor> as ORACLE, SAPDB, MS_SQL_SERVER, DB2_UDB_AS400 or DB2_UDB_OS390 but INFORMIX is not an accepted value.
Is there any way to define how this SQL query is build?
Thanks in advance.The return type of the finder method defined in the remote home interface is either the entity bean's remote interface or a collection of objects implementing the entity bean's remote interface. The return type of the finder method defined in the local home interface is either the entity bean's local interface or a collection of objects implementing the entity bean's local interface
Maybe you are looking for
-
How could I replace a open document name with a new name? I have a script that creates the new name but I can't figure out how to send the new name back to photoshop replacing the open document name. Here is the current script: layerN = activeDocumen
-
Hi, can somebody help me to understand why does error occur in this example? <% if (k.equals("1")) {%> html tags <%} if (k.equals("2")) {%> html tags <%}%> If there is only one condition it works, but if tere are two, the second condition lead to the
-
This is occuring for both old and recent downloads.
-
Hello, I am trying to write an XPath syntax query to retrieve some specific child nodes in a loop (in PLSQL) from the following document excerpt.. <?xml version="1.0" encoding="utf-8" ?> <Request RequestNumber=""> <TargetServers> <TargetServer> <HARD
-
I always got error message when opening BlackBerry App World using 3g
Hi there, I always got error message when opening BlackBerry App World using 3g network, but it's fine if I open it through wifi network. Does anyone ever had the same problem and how to fix it? Thanks.