Comp. Primary key class-field mapping to DB columns problem.(EJB 2.0 CMP)
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!
Similar Messages
-
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 -
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. -
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. -
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 -
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. -
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 :-) -
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 -
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..
-
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 -
Primary key violation exception in auto increment column
Hi All,
I am facing one issue in Multi threaded environment.
I am getting Primary key violation exception in auto increment column. I have a table and the primary key is the auto increment column, and I have a trigger which is populating this column.
5 threads are running and inserting the data in the table and throwing Primary key violation exception randomly.
create table example (
id number not null,
name varchar2(30)
alter table example
add constraint PK1example primary key (id);
create sequence example_id_seq start with 1 increment by 1;
create or replace trigger example_insert
before insert on example
for each row
begin
select example_id_seq.nextval into :new.id from dual;
end;
Any idea how to handle auto increment column(trigger) in Multi threaded environment??
Thanks,user13566109 wrote:
Thanks All,
Problem was in approach; removed the trigger and placed a seq.nextval in insert query. It has resolved the issue.I very much suspect that that was not the issue.
The trigger would execute for each insertion and the nextval would have been unique for each insertion (that's how sequences work in oracle), so that wouldn't have been causing duplicates.
I suspect, more likely, that you had some other code somewhere that was using another sequence or some other method of generating the keys that was also inserting into the same table, so there was a conflict in the sources of the sequences being generated.
The way you showed you had coded above, was a perfectly normal way to assign primary keys from a sequence, and is not a problem in a multi user/threaded environment. -
If I have an EntityBean that mappes to two tables within one database, when I create
that EJB, whoes reponsibilty to generate the primary key in database table? The
RDBMS or EJB?
Thanks,
JWRefer to http://e-docs.bea.com/wls/docs81/faq/ejb.html/#257430
"Jingwei Zhang" <[email protected]> wrote:
>
If I have an EntityBean that mappes to two tables within one database,
when I create
that EJB, whoes reponsibilty to generate the primary key in database
table? The
RDBMS or EJB?
Thanks,
JW -
Every table need primary key in toplink mapping to fetch the data
Hi everyone,
we are working on toplink mapping , it neccessary every table needs primary key. if yes, gave me example.Hi everyone,
Alterations in database will not be automatically reflected in toplink so, there is any alternative
with regards
abusufian -
How to use primary key in sql combined from 2 columns
table1
primary key = orderid+custname
orderid custname address
8889 Adrian london
8867 Clara manchester
2229 Peter warwick
table2
primary key = orderid+custname
orderid custname qty price
8889 Adrian 10 2500
8865 Adrian 20 9483
8867 Clara 30 3993
5869 Clara 15 1828
2290 Peter 10 2102
2298 Peter 13 3839
then how do i query ?
SQL> select t1.orderid, t1.custname, t1.address, t2.qty, t2.price from
table1 t1, table2 where ? = ?
what's the "?" should be ????
it doesn't work if i enter the primary constraint key for each table.
thanks.thanks, it works ;)
btw, do you know how about the date field ?
what if one of the field in table1 is 12/12/2005 14:30
and table2 is 15/12/2005
table1
orderid orderdate
1234 12/12/2005 14:30
2234 15/12/2005 13:45
table2
orderid orderdate
1234 12/12/2005
2234 15/12/2005
so the query
select t1.orderid as t1 t1.orderdate , t2.orderid as t2, t2.orderdate from
table1 t1, table2 t2 where t1.orderid = t2.orderid
and to_char(to_date(t1.orderdate, 'dd/mm/yyyy hh24:mi'), 'dd/mm/yyyy') = t2.orderdate
thanks. -
IR - if count (primary key) cannot change to count different column
Apex 4.1.1.00.23 Windows 7 IE8 / Firefox 16
If I add a Group By and Count to an Interactive report and choose the primary key column as the one to Count, run the report and then edit the Group By to count a different column, the result set does not change, and if I edit the Group By again it shows that the Counted column has reverted back to the primary key column.
If I initially choose a different column I can change it and rerun the report successfully, but once I choose the primary key column it cannot be changed. This seems to happen on all applications and all browsers. Is it a bug in Apex?
Thanks,
Nick.I've tried this in 4.1.0.00.32: works normally. In 4.1.1.00.23 however i'm getting the weird behaviour: you can count on any column, but the moment you count the same column as the one grouped on you can not change the column back to another one anymore. Something which works fine in 4.1.0.00.32.
Maybe you are looking for
-
Is there any possible way of installing flash player onto an ipad?
Please help if you can.
-
Mapping execution not finish never
hello, my problem is that when I try to execute some mapping this start to execute but it never finishes (or it takes too much) and the server where database is running is hung so we have to re-start the machine. Anybody knows if I can set some param
-
Hi everyone, With the latest updates to the Airport Extreme that allow it to effectively become a Time Capsule, I decided that I would plug in a hard drive I have lying around to set up a backup system for my home. However, I use my Macbook Pro at wo
-
Looking for some help and advice please. Thinking of changing our online shop around and see there are a number of extensions available for Dreamweaver. Can anyone recommend one they have used that was particularly successful and easy to use and set
-
Backup to external disc problem with Time Machine
After successfully backing up Time Machine to a LaCie Group SA external disc for months, the backup now fails with the error message that the disc is "read-only" When looking at the properties of the external disc, it shows that the administrator and