Why in primary key class overrided in EJB?
in EJB ... why in primary key class Object's Equals() and HashCode() method's were overridden ??
please see the other question.. sorry for inconvinance..
Similar Messages
-
Why do we need a primary key class?
i found a sample ejb, which contains a class only used to store the primary key. is it necessary? why? i guess it's for security issue, anybody can help me to clarify? thanks in advance!
A primary key class is used next to an entity bean. It's used to represent the primary key of the table on which the entity bean is mapped.
When the primary key of the table is only one column, you don't need to implement a primary key class. You can then define java.lang.Integer or java.lang.String or another build in Java object in you deployment descriptor. -
Hi!
I have deal with EJB 2.0 CMP bean.
I have a composite PK so use the java class to store it. And there is a corresponding field in the Entity Bean with its primary key class type.
The problem is: when deployment tool creates sql query for the findByPrimaryKey(PKClass ck)
where ck is an object with 3 fielde : a_id, b_id, c_id.
it says:
<sql>SELECT "ck" FROM "MyTable" WHERE "ck" = ? </sql>
And it means by the "ck" simple a column in DB but NOT the composite key which has to be splited into 3 different fields. So the container can't do the proper mapping.
Does anyone know solutions?I was wrong about primary key class fields, take a look at Ejb2.0 Specification (10.8.2):
The primary key class must be public, and must have a public constructor with no parameters.
All fields in the primary key class must be declared as public.
The names of the fields in the primary key class must be a subset of the names of the container-managed
fields. (This allows the container to extract the primary key fields from an instance�s container-managed
fields, and vice versa.)
Right now I'm using BMP and I don't have this problems. Primary keys, calculated fields and types not supported by the DB can be easily achieved. But I understand your interest on CMP, is clearly evolving! -
Hi there,
In an entity bean, why do we need a primary key class? I read from some book that an entity bean can work all right without it. Is it true?
RegardsHi,
In cases of Primary Keys defined as Strings, the creation of Primary Key class can be ignored by the bean provider/developer. However the primary key must be generated in the program either in the setprimarykey() defined in class implementing the EntityBean interface.
The ejb-jar.xml can have the entry as <prim-key-class>java.lang.String</prim-key-class> in such cases of both CMP and BMP EB.
As long as you generate the Primary Key and pass it in the various callback methods like ejbFindByPrimaryKey, ejbCreate etc, you can avoid creating the primary key class.
Remember in CMP the ejbCreate in the Home interface returns NULL while in BMP it is the primary key returned.
HTH,
Seetesh -
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. -
Foreign Keys in Primary Key Class
I am a newbie on toplink. I am getting an error when i run ejbc against the jar file with EJB2.0. One of the primary key classes two primary keys and both are foreign Keys to other tables. Primary Key class looks like this:
public class LcaCyberzoneAssocPK implements java.io.Serializable
public ValueHolderInterface lcaHolder;
public ValueHolderInterface cyberzoneDefHolder;
public LcaCyberzoneAssocPK(ValueHolderInterface lcaHolder,
ValueHolderInterface cyberzoneDefHolder)
super();
this.lcaHolder = lcaHolder;
this.cyberzoneDefHolder = cyberzoneDefHolder;
Bean Class has following four methods:
public abstract Lca getLcaHolder()
throws RemoteException;
public abstract CyberzoneDef getCyberzoneDefHolder()
throws RemoteException;
public abstract void setLcaHolder(Lca arg1)
throws RemoteException;
public abstract void setCyberzoneDefHolder(CyberzoneDef arg1)
throws RemoteException;
The error it is throwing is:
ERROR: Error from ejbc: In EJB LcaCyberzoneAssoc, lcaHolder is declared as oracle.toplink.indirection.ValueHolderInterface in the
pk class, but the corresponding getLcaHolder() method in the bean class returns com.qwest.danconfig.server.ejb.entity.Lca. These t
ypes must match.
Can you please help how to fix this or what is the correct way of doing it.
Second question is, is there any document which explains migrating toplink from EJB1.1 to EJB2.0?
ThanksThe EJB 2.0 spec does not really allow relationships in the primary key class. You may be able to get it to work by using the EJB classes, not ValueHolderInterface in primary key class.
Otherwise you will need to double map the foreign key fields as direct fields to be compliant with the spec. You can still have the one-to-one mappings but your model will need to keep both in synch and mark the one-to-one mappings as read-only. -
CMP Entity Beans with custom finders an primary key class
Hi everybody.
I've got a Entity with a primary key class and a custom finder. I've defined
the finder into the xml file like iPlanet's documentation say, but, when I
try to run the aplication I get the following error:
Exception: SERVLET-run_failed: Failed in running template:
/PruebaGI/PruebaGI/pruebagi.jsp, java.lang.ClassCastException:
com.netscape.server.deployment.SessionBeanDescriptor
Exception Stack Trace:
java.lang.ClassCastException:
com.netscape.server.deployment.SessionBeanDescriptor
at
com.netscape.server.servlet.servletrunner.AppInfo.popWebAppDescriptor(Unknow
n Source)
at com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
Source)
at com.netscape.server.servlet.servletrunner.ServletRunner.callJSP(Unknown
Source)
at
com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.callJsp
Compiler(Unknown Source)
at
com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.callUri
(Unknown Source)
at
com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.callUri
RestrictOutput(Unknown Source)
at
com.netscape.server.servlet.platformhttp.PlatformRequestDispatcher.forward(U
nknown Source)
at com.netscape.server.servlet.jsp.JSPRunner.service(Unknown Source)
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).
Could anybody help my? I need to resolve this question quickly.
Thx
..Hi Juan,
Sounds like you've defined either a java.lang.String where it should have
said Java.util.Vector (or the other way around) in the part of the
deployment descriptor that defines your custom finder method parameter.
Regards,
Raymond
"Juan Jos� Ayuso" <[email protected]> wrote in message
news:[email protected]...
Hi everybody.
I've got a Entity with a primary key class and a custom finder. I'vedefined
the finder into the xml file like iPlanet's documentation say, but, when I
try to run the aplication I get the following error:
Exception: SERVLET-run_failed: Failed in running template:
/PruebaGI/PruebaGI/pruebagi.jsp, java.lang.ClassCastException:
com.netscape.server.deployment.SessionBeanDescriptor
Exception Stack Trace:
java.lang.ClassCastException:
com.netscape.server.deployment.SessionBeanDescriptor
at
com.netscape.server.servlet.servletrunner.AppInfo.popWebAppDescriptor(Unknow
n Source)
at com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
Source)
atcom.netscape.server.servlet.servletrunner.ServletRunner.callJSP(Unknown
Source)
at
com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.callJsp
Compiler(Unknown Source)
at
com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.callUri
(Unknown Source)
at
com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.callUri
RestrictOutput(Unknown Source)
at
com.netscape.server.servlet.platformhttp.PlatformRequestDispatcher.forward(U
nknown Source)
at com.netscape.server.servlet.jsp.JSPRunner.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
Source)
atcom.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).
Could anybody help my? I need to resolve this question quickly.
Thx -
Deployment Tool Problem (J2EE -Composite primary Key Class)
Hi !!
e.g. I have an entiybean which has composite primary key class. So while deploying in J2EE tool u need to specify the Primary key class and the primary key field. well in case of a composite primary key class(if u have more than one field)...how do u declare all the fields for primary key class....
if u r not getting me please tell me... See in J2EE deployment tool there is on section called Entity..in that see the Primary Key class (there u specify the Primary key class) and the Primary Key Field Name (the field name) Here u can just give only one Field name..if you have mulitple fields, then where you will specify... Please let me know..
if anybody wants the code I will give the code...Please try to help..(how to deploy this kind of entity bean in J2EE deployment tool)
-BhumikaHi Bhumika,
in case you have more than one field you need to write a Primary key class where the fields you want to be the key are member variables.
your p.key class could look like this (it has to implement hash() and equals() ):
public class PersonPK implements java.io.Serializable
public int person_ID;
public PersonPK()
public PersonPK(int aPersonId)
person_ID = aPersonId;
public int hashCode()
return person_ID;
public boolean equals(Object ob)
if (ob == this) return true;
if (!(ob instanceof PersonPK)) return false;
PersonPK other = (PersonPK) ob;
if (person_ID != other.person_ID) return false;
return true;
-Hope this helps a bit,
Anke -
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 :-) -
Primary Key Class Indicator mapping
Hi
We are using a Class Inidcator Field as described within Toplink documentation.
We have encountered a problem, relating to the Class Indicator field not being populated within the Object within the cache,
For example, the creation of one of our indictated objects successfully inserts the relevant class indicator value in the database, but the Object in the cache does not have the value set. This casues issues when attempting to identify the object in the cache.
When re-reading the documentation at http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/descun007.htm#sthref2899 I noted the following line:
"If the indicator field is part of the primary key, define a write-only transformation mapping for the indicator field (see Chapter 48, "Configuring a Relational Transformation Mapping"). "
However following the documentaion trail, to http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/relmapun013.htm#CHDDBJJJ there is a statement:
"Use transformation mappings only when mapping multiple fields into a single attribute. Because of the complexity of transformation mappings, it is often easier to perform the transformation with a converter or getter and setter methods of a direct-to-field mapping. See Chapter 38, "Configuring a Relational Direct-to-Field Mapping" for more information."
Is there any definitive answer to correctly use a Class Indicator on a Primary Key field.
Many Thanks
MarcHi,
I'm still really struggling to find the correct way of implementing the mapping, as described within the documentation.
As per the amended documentation quoted above, we are using a Primary Key field as the indentifier of a Class Indicator Mapping, and should therefore implement a "Read-Only Transformation Mapping for the indicator field".
The explanation of how to implement Transformation Mappings in section 33-15,
stipluates that both the "attribute transformer" - reading from the database,
and the "field transformer" must be specified. By default, this would appear to
be describing a read and write transformational mapping. Please correct me, if
I am wrong.
Therefore, we have currently found no method of implementing a "Read Only"
transformational mapping for a Class Indicator Mapping.
Any assistance in advising of the method of implementing this, would be greatly appreciated.
Regards
Marc -
Why should primary key be the first column in a table
Hi,
I'm trying to build a case to alter a table in production with a composite key . I have PK columns at the start of table which is how it should be , but the issue is down the line , another column was added at the end and the same was added to composite
key .
issue is as PK arranges records physically where it creates a clustered index, as far as my knwoledge goes, data is ordered initially by the three fields (composite keys) and then ordered again by another composite key field as they are not
defined in a set , will this cause any performance bottle necks as it's a stage table to populate a fact if so how ??
below is the table structure..
Any help in this regard is appreciated :)PRIMARY KEY as first column is just a convention.
The PRIMARY KEY columns can be anywhere in a table.
I don't see any advantage to the 5-column PRIMARY KEY.
I would design it with INT IDENTITY (or SEQUENCE OBJECT) SURROGATE PRIMARY KEY.
You can make the 5-columns a UNIQUE key or unique index.
Kalman Toth Database & OLAP Architect
Free T-SQL Scripts
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
EJB Primary Key not found in lock manager - Container BUG?
I have an EJB entity bean whose primary key class implementation is pretty simple, consisting of two strings. For the MOST part, it seems to work properly, but every so often I see the following message in my application server log.
####<Sep 17, 2008 10:03:27 AM EDT> <Warning> <JTA> <armantac22> <AdminServer> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1221660207187> <BEA-110401> <Ignoring error in afterCompletion. Object=weblogic.ejb.container.internal.TxManager$TxListener@1906466, Exception=javax.ejb.EJBException: [EJB:010108]The EJB Lock Manager has received an unlock request from EJB:PortfolioMetaData with primary key:[ObjectPK: type: PortMetaData name: PortMetaData]. However, this primary key could not be found in the Lock Manager. This indicates either an EJB container bug, or the equals and hashCode methods for the primary key class:com.armanta.ejb.ObjectPK are implemented incorrectly. Please check the equals and hashCode implementations.
javax.ejb.EJBException: [EJB:010108]The EJB Lock Manager has received an unlock request from EJB:PortfolioMetaData with primary key:[ObjectPK: type: PortMetaData name: PortMetaData]. However, this primary key could not be found in the Lock Manager. This indicates either an EJB container bug, or the equals and hashCode methods for the primary key class:com.armanta.ejb.ObjectPK are implemented incorrectly. Please check the equals and hashCode implementations.
at weblogic.ejb.container.locks.ExclusiveLockManager$LockBucket.unlock(ExclusiveLockManager.java:409)
at weblogic.ejb.container.locks.ExclusiveLockManager.unlock(ExclusiveLockManager.java:170)
at weblogic.ejb.container.manager.ExclusiveEntityManager.afterCompletion(ExclusiveEntityManager.java:723)
at weblogic.ejb.container.manager.ExclusiveEntityManager.afterCompletion(ExclusiveEntityManager.java:667)
at weblogic.ejb.container.internal.TxManager$TxListener.afterCompletion(TxManager.java:984)
at weblogic.transaction.internal.ServerSCInfo.callAfterCompletions(ServerSCInfo.java:862)
at weblogic.transaction.internal.ServerTransactionImpl.callAfterCompletions(ServerTransactionImpl.java:2913)
at weblogic.transaction.internal.ServerTransactionImpl.afterCommittedStateHousekeeping(ServerTransactionImpl.java:2806)
at weblogic.transaction.internal.ServerTransactionImpl.setCommitted(ServerTransactionImpl.java:2851)
at weblogic.transaction.internal.ServerTransactionImpl.globalRetryCommit(ServerTransactionImpl.java:2650)
at weblogic.transaction.internal.ServerTransactionImpl.globalCommit(ServerTransactionImpl.java:2570)
at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:277)
at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:226)
at weblogic.ejb.container.internal.BaseEJBHome.postHomeInvoke(BaseEJBHome.java:389)
at weblogic.ejb.container.internal.EntityEJBHome.findByPrimaryKey(EntityEJBHome.java:408)
at com.armanta.ejb.portfolio.PortfolioMetaData_a4zvzk_HomeImpl.findByPrimaryKey(PortfolioMetaData_a4zvzk_HomeImpl.java:64)
at com.armanta.ejb.portfolio.PortfolioMasterBean.getPortfolioMetaData(PortfolioMasterBean.java:313)
at com.armanta.ejb.portfolio.PortfolioMaster_fmk9e8_EOImpl.getPortfolioMetaData(PortfolioMaster_fmk9e8_EOImpl.java:64)
at com.armanta.ejb.portfolio.PortfolioMaster_fmk9e8_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:517)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:224)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:407)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:403)
at weblogic.rmi.internal.BasicServerRef.access$300(BasicServerRef.java:56)
at weblogic.rmi.internal.BasicServerRef$BasicExecuteRequest.run(BasicServerRef.java:934)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)
I checked the equals and hashCode implementations and nothing pops out at me. Once this happens, the EJB seems to get messed up in the database and I lose information!
Here is the class implementation along with its superclass. I don't see anything blatant. Sorry for the lack of indentation, my original post was indented.
Thanks
Eric
public class ObjectPK extends ArmantaPK {
private String type;
private String name;
private ObjectPK() {
super();
public ObjectPK(String type, String name) {
super();
this.type = type;
this.name = name;
public String getName() {
return name;
public String getType() {
return type;
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[ObjectPK:");
buffer.append(" type: ");
buffer.append(type);
buffer.append(" name: ");
buffer.append(name);
buffer.append("]");
return buffer.toString();
* Returns <code>true</code> if this <code>ObjectPK</code> is the same as the o argument.
* @return <code>true</code> if this <code>ObjectPK</code> is the same as the o argument.
public boolean equals(Object o) {
if (this == o) {
return true;
if (!super.equals(o)) {
return false;
if (o == null) {
return false;
if (o.getClass() != getClass()) {
return false;
ObjectPK castedObj = (ObjectPK) o;
return ((this.type == null ? castedObj.type == null : this.type
.equals(castedObj.type)) && (this.name == null
? castedObj.name == null
: this.name.equals(castedObj.name)));
* Override hashCode.
* @return the Objects hashcode.
public int hashCode() {
int hashCode = super.hashCode();
hashCode = 31 * hashCode + (type == null ? 0 : type.hashCode());
hashCode = 31 * hashCode + (name == null ? 0 : name.hashCode());
return hashCode;
public Object clone() {
ObjectPK inst = new ObjectPK();
inst.type = this.type == null ? null : new String(this.type);
inst.name = this.name == null ? null : new String(this.name);
return inst;
public abstract class ArmantaPK implements Serializable, Cloneable, Comparable {
// Enforce compatability with future versions
private static final long serialVersionUID = 1980721424128862564L;
// Cache the hash code
private transient int hash = 0;
* Clones a primary key. Note that this is not a deep copy.
* @return the cloned primary key
public Object clone() throws CloneNotSupportedException {
ArmantaPK newKey = (ArmantaPK) super.clone();
newKey.hash = 0;
return newKey;
* Compare the specified object with this key for equality.
* Implementations should return <tt>true</tt>
* if and only if the specified object is also a key
* of the same class and all corresponding attributes in the keys are
* <i>equal</i>.
* @param other the object to be compared for equality with this key.
* @return <tt>true</tt> if the specified object is equal to this key.
public boolean equals(Object other) {
return other instanceof ArmantaPK;
* This implementation only returns an empty String.
* @return String
public String toString() {
return "";
* Return the hash code value for this key. Implemented to call the
* key's <code>computeHash</code> method and cache the result for
* faster operation. Classes extending <code>ArmantaPK</code> should
* only implement <code>computeHash</code>.
* @return int
public int hashCode() {
if (hash == 0) {
hash = computeHash();
return hash;
* @y.exclude
* Compute a hash code for this key. This is the method that should
* be overridden by sub-classes.
* @return int
protected int computeHash() {
return 0;
* @y.exclude
* After called, will force the hash code to get recomputed.
public void rehash() {
hash = 0;
* Compares this <tt>ArmantaPK</tt> to another object by comparing
* their string representations.
* @return an integer based upon comparing the <tt>ArmantaPK</tt>s string
* representations
public int compareTo(Object o) {
return toString().compareTo(o.toString());
}We are experiencing a similar error after upgrading 9.2 to 9.2 MP3. We do not want to upgrade to 10g at this time. Is there a patch we can download with the fix?
-
Hi all,
I am new to ejb. I am trying to create a BMP bean for a particular table which is having composite primary key. I made a primary key class for that and I have done all the important things required for creating such a class viz,
1) implement java.io.Serializable
2) define all fields of the primary key as public variables in the class
3) override public int hashCode()
and public boolean equals (Object obj)
but when i deploy the beans in jboss it is giving
"The primary key class must override equals()" error
what could be the problem
Thanks in advance
BinnyAdd a method boolean equals(Object o) see java.lang.Object. This is required for comparisons, also hashCode needed.
-
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 an EJB that has no primary key
I want to create an EJB for a table that has no primary key using
J-developer but I get an error like this :
"cmp-field of type 'java.lang.Long' does not have a no-arg constructor which is needed for properties/fields based mapping"
How can I go on?Sorry primitives are NOT allowed to be primary Key candidates - OOPS!
it looks like you may have to use String
or provide your own Primary Key class which (perhaps) extends Long
Maybe you are looking for
-
Upgrading from OS 8 to OS 8.5 and then to 8.6.
Hello, I would like to know, please, if I need to reinitialize my hard drive on a Performa 6220 CD (Power Pc) in order to install OS 8.5 over my OS 8.0 and the subsequent upgrde to OS 8.6? I do not know if a computer this old will allow OS 9.0 and I
-
Nokia X6 and contacts bar re visited?
Has anyone had any issues with the latest updates for the X6 16GB? A previous update V30 I think had the contacts bar disappearing. I was wondering if this was happening with the latest update. Any feed back would be most welcome. I had to get a new
-
Cannot change number of rows in layout set
I have created a layout set with a custom Collection Grid Renderer to show XML forms news items. I have changed the <i>number of rows</i> property to <i>3</i> to set the number of items to display to 3, but only one item is displayed. I have changed
-
Issue in query transport ( formula variable)
Hi Experts, I have issue while transporting a query. I have created two formaula variables, with them created a calculated keyfigure. The transport of this query was failed with return code 8 with Error message 'Element 4XDRFT... is missing in versio
-
In Safari 4 beta when a new window was opened by a link when clicked with the middle mouse button it would load in the background. Since the update to Safari 4 (release) this no longer occurs. Is there a way to get this functionality back? Furthermor