Exception Description: Entity class [] has no primary key....
Received the following error in jdeveloper - some info on how to fix would be greatly appreciated
[EclipseLink/JPA Client] Adding Java options: -javaagent:C:\oracle\MiddlewareNew\jdeveloper\modules\oracle.toplink_11.1.1\eclipselink.jar
C:\Oracle\MiddlewareNew\jdk160_05\bin\javaw.exe -client -classpath C:\JDeveloper\mywork\APP_CM_AUTONUM_GEN\.adf;C:\JDeveloper\mywork\APP_CM_AUTONUM_GEN\SAM_CM_AUTONUM_GEN\classes;C:\oracle\MiddlewareNew\jdeveloper\modules\oracle.toplink_11.1.1\toplink.jar;C:\oracle\MiddlewareNew\jdeveloper\modules\oracle.toplink_11.1.1\antlr.jar;C:\oracle\MiddlewareNew\modules\com.bea.core.antlr.runtime_2.7.7.jar;C:\oracle\MiddlewareNew\modules\javax.persistence_1.0.0.0_1-0.jar;C:\oracle\MiddlewareNew\jdeveloper\modules\oracle.toplink_11.1.1\eclipselink.jar;C:\oracle\MiddlewareNew\jdeveloper\modules\oracle.xdk_11.1.1\xmlparserv2.jar;C:\oracle\MiddlewareNew\jdeveloper\modules\oracle.xdk_11.1.1\xml.jar;C:\oracle\MiddlewareNew\modules\javax.jsf_1.2.0.0.jar;C:\oracle\MiddlewareNew\modules\javax.ejb_3.0.1.jar;C:\oracle\MiddlewareNew\modules\javax.enterprise.deploy_1.2.jar;C:\oracle\MiddlewareNew\modules\javax.interceptor_1.0.jar;C:\oracle\MiddlewareNew\modules\javax.jms_1.1.1.jar;C:\oracle\MiddlewareNew\modules\javax.jsp_1.1.0.0_2-1.jar;C:\oracle\MiddlewareNew\modules\javax.jws_2.0.jar;C:\oracle\MiddlewareNew\modules\javax.activation_1.1.0.0_1-1.jar;C:\oracle\MiddlewareNew\modules\javax.mail_1.1.0.0_1-1.jar;C:\oracle\MiddlewareNew\modules\javax.xml.soap_1.3.1.0.jar;C:\oracle\MiddlewareNew\modules\javax.xml.rpc_1.2.1.jar;C:\oracle\MiddlewareNew\modules\javax.xml.ws_2.1.1.jar;C:\oracle\MiddlewareNew\modules\javax.management.j2ee_1.0.jar;C:\oracle\MiddlewareNew\modules\javax.resource_1.5.1.jar;C:\oracle\MiddlewareNew\modules\javax.servlet_1.0.0.0_2-5.jar;C:\oracle\MiddlewareNew\modules\javax.transaction_1.0.0.0_1-1.jar;C:\oracle\MiddlewareNew\modules\javax.xml.stream_1.1.1.0.jar;C:\oracle\MiddlewareNew\modules\javax.security.jacc_1.0.0.0_1-1.jar;C:\oracle\MiddlewareNew\modules\javax.xml.registry_1.0.0.0_1-0.jar;C:\oracle\MiddlewareNew\wlserver_10.3\server\lib\weblogic.jar -javaagent:C:\oracle\MiddlewareNew\jdeveloper\modules\oracle.toplink_11.1.1\eclipselink.jar SAM.CMAUTONUMGENClient
java.lang.reflect.InvocationTargetException
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 sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
Caused by: java.lang.reflect.InvocationTargetException
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 org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializerAgent.initializeFromAgent(JavaSECMPInitializerAgent.java:45)
at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializerAgent.premain(JavaSECMPInitializerAgent.java:38)
... 6 more
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 1.0.2 (Build 20081024)): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [SAM_CM_AUTONUM_GEN] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 1.0.2 (Build 20081024)): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class oracle.SamCmAutonumGen] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then please make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:870)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:101)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initPersistenceUnits(JPAInitializer.java:149)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initialize(JPAInitializer.java:135)
at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializer.initializeFromAgent(JavaSECMPInitializer.java:145)
... 12 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 1.0.2 (Build 20081024)): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [SAM_CM_AUTONUM_GEN] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 1.0.2 (Build 20081024)): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class oracle.SamCmAutonumGen] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then please make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:210)
... 17 more
Caused by: Exception [EclipseLink-7161] (Eclipse Persistence Services - 1.0.2 (Build 20081024)): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class oracle.SamCmAutonumGen] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then please make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.exceptions.ValidationException.noPrimaryKeyAnnotationsFound(ValidationException.java:1245)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.validatePrimaryKey(EntityAccessor.java:1173)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.process(EntityAccessor.java:486)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:443)
FATAL ERROR in native method: processing of -javaagent failed
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:303)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:830)
... 16 more
Exception in thread "main" Process exited with exit code 1.
Hi,
you may want to try the J2EE forum here on OTN in case you don't get a sufficient answer to the problem.
Frank
Similar Messages
-
Insert values in multiple tables. One of the tables has complex primary key.
Hello, I am using Jdeveloper version 11.1.2.3.0
I have a table FORM_TYPE and another table Str. The Str table is used to translate strings from the table name which are read from another program from the database and used to generate forms..
The FORM_TYPE table has a relation to the STR table via formtype.title_str_id = str.str_id.
The STR table has a primary key that is depending on mf_language and str_id columns. I generated entity for the STR table but can't insert from the application module new values for some reason... It says the record invalidates its own entity..
I am trying to create a table that will be editable and will have the columns Description, Name, Str in English, Str in French etc...
Want to create a Form_Type and in the same time to insert new values for each language... But can't make the inserts of the new STR work..
Also the FormType.TITLE_STR_ID has many values null already in the database.
SELECT FormType.DESCRIPTION,
FormType.FORM_TYPE_ID,
FormType.NAME,
FormType.PAPER_REPORT_FORMAT,
FormType.PAPER_REPORT_NAME,
FormType.TITLE_STR_ID,
en.str en_str,
en.str_id,
en.object_name en_object_name,
fr.str,
fr.str_id,
fr.object_name,
du.str,
du.str_id,
du.object_name,
bg.str,
bg.str_id,
bg.object_name
FROM FORM_TYPE FormType,
(select str.str_id, str.mf_language_id, str.str, str.object_name
from mf_language ml, str
where ml.mf_language_id = str.mf_language_id
and ml.code ='en') en
, (select str.str_id, str.str, str.object_name
from mf_language ml, str
where ml.mf_language_id = str.mf_language_id
and ml.code ='fr') fr,
(select str.str_id, str.str, str.object_name
from mf_language ml, str
where ml.mf_language_id = str.mf_language_id
and ml.code ='du') du,
(select str.str_id, str.str, str.object_name
from mf_language ml, str
where ml.mf_language_id = str.mf_language_id
and ml.code ='bg') bg
WHERE
formtype.title_str_id = en.str_id and
formtype.title_str_id = fr.str_id and
formtype.title_str_id = du.str_id and
formtype.title_str_id = bg.str_idTried that I made view links and associations but still can't insert in both tables at once... Could be because the tables aren't having relationship between them or because the STR table has a (STR_ID, MF_LANGUAGE_ID) primary key...
-
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 -
How to make a form using a wizard when the table has no primary key ?
Hi,
I want to make a form to update, delete a table. The table has no primary key. The problem is that the Wizard ask for a primary key.
How to avoid using a primary key ? i mean I don't want to create a primary key if is is possible.
I would like to use the wizard; is it possible ?
Thank you for your kind answers.
ChristianI believe the key is choosing 'Interactive' as opposed to 'Classic' in the implementation and then you can choose 'Existing Trigger' for the primary key source and it should work to use an existing column as your proimary key.
-
Need to create form on a table with report with a table has NO primary key
Hi, I tried to created some insert/update/delete form+report in an application, it works fine only if the table has primary key. Does anyone know how to create the same functionality with a table with no primary key? I saw an application is built on older version of htmldb that is using tables with no primary keys at all.
Here are the specific issues that I am facing:
- I am building some Form on a table with Report, it requires the table with primary key for form to update. Is there a workaround that I can use tables that has no primary keys at all?
- Say if primary key is necessary in the previous report+form, but the maximum number of columns that I can use to composed a primary is only 2 for that Form-Report, I cannot find anything handling > 2 primary key. Do you know if there are some ways to composite a primary key from many columns together?
Your help is really appreciated.
Thanks,
AngelaSorry to ask response so late. I had no time to get back to that issue before.
Regarding the triggers, I can make it work for the update, but not the insert.
Here is my trigger:
create or replace trigger STATUS_T1
instead of insert on STATUS
begin
insert into STATUS ("LABEL", "AREA", "OWNER", "TEST_NAME", "STATUS", "REMARKS", "BUGS", "DEV_MGR", "TEST_BY_DATE")
values(:new.LABEL, :new.AREA, :new.OWNER, :new.TEST_NAME, :new.STATUS, :new.REMARKS, :new.BUGS, :new.DEV_MGR, :new.TEST_BY_DATE);
end;
by any chance, you can notify what is wrong?
I already skip the ROWID when inserting to the view STATUS, but I cannot figure out what is wrong when inserting a new record to that view.
It gave me the following errors:
ORA-06550: line 1, column 38: PL/SQL: ORA-00904: "ID": invalid identifier ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored
Error Unable to process row of table STATUS
Then, I turned to debug mode, I am thinking that maybe because I use a HIDDEN item to hold the value of ROW_ID as I use the rowid (called ID in the view) to retrieve the record as a column link from previous page. What do you think?
Thanks again,
Angela -
I'm using toplink with JPA. it was able to deploy to OC4J succesfully. however, when I deploy to oracle application server 10.1.3, I got the following error:
has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass.
I do have @Id defined for id property. I tried to move @Id annotation to getId() method, instead of id property, the deployment succesfully.
I have many entities need to be changed. i'm wndoring if there is configuration or if it is bug of OAS 10.1.3Hello,
You haven't mentioned which version of OC4J you are successfully deploying to. If it is not 10.1.3, then you might try upgrading your OAS server so that its version matches the OC4J version you are using. OAS 10.1.3 only had very limited JPA support, and so it is advisable to use OAS 10.1.3.3 anyway.
Best regards,
Chris -
How do I create an Entity Bean with unknown primary keys
Hi,
Can a good folk help me.
I am mapping an entity bean to an oracle table for the purpose of logging . I do not need a primary key contraint on this table. How do I specify in my entity bean file descriptor not to use any field for primary key ...
I have done this so far...
in my ejb.xml file - I set....
<prim-key-class>java.lang.Object</prim-key-class>
and deleted ....
<primkey-field>...</primkey-field>
My table structure is .....
CREATE TABLE FAMS_REQUEST_LOG (
EDITEDBY VARCHAR2(20),
OLDTRANSDATE DATE,
REQUESTID VARCHAR2(30) NOT NULL,
OLDQTY NUMBER(20),
NEWQTY NUMBER(20),
NEWTRANSDATE DATE)
but I still get this error message on deploying...
[#|2006-03-01T14:30:29.250+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.tools.deployment|_ThreadID=19;|Total Deployment Time: 11000 msec, Total EJB Compiler Module Time: 0 msec, Portion spent EJB Compiling: 0%|#]
[#|2006-03-01T14:30:29.265+0100|SEVERE|sun-appserver-pe8.1_02|javax.enterprise.system.tools.deployment|_ThreadID=19;|Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: Fatal Error from EJB Compiler -- JDO74046: JDOCodeGenerator: Caught a MappingConversionException loading or creating mapping model for application 'fixassetenterpriseapp' module 'FixAssetEnterpriseApp-EJBModule': JDO71030: There is no column in table FAMS_REQUEST_LOG which can be used to support the servers implementation of unknown key classes.
at com.sun.ejb.codegen.CmpCompiler.compile(CmpCompiler.java:274)
at com.sun.ejb.codegen.IASEJBC.doCompile(IASEJBC.java:615)
at com.sun.ejb.codegen.IASEJBC.ejbc(IASEJBC.java:563)
at com.sun.enterprise.deployment.backend.EJBCompiler.preDeployApp(EJBCompiler.java:340)
at com.sun.enterprise.deployment.backend.EJBCompiler.compile(EJBCompiler.java:209)
at com.sun.enterprise.deployment.backend.AppDeployer.runEJBC(AppDeployer.java:284)
at com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:176)
at com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:107)
at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:146)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:71)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:633)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:188)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:520)
at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:143)
at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:172)
|#]
Dotunyou will have to create a sequence and a trigger
CREATE SEQUENCE <SEQUENCE NAME>
INCREMENT BY 1
START WITH 1
NOCACHE
/this sequence will guarantee that each requested number is unique
the trigger will select from this sequence and insert the obtained value in the new record
CREATE OR REPLACE TRIGGER <TRIGGER NAME>
BEFORE INSERT ON <TABLE NAME>
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
select
<SEQUENCE NAME>.nextval
into
:NEW.<COLUMN NAME>
from
dual;
END;
[/CODE]
this will always take the value from the sequence, even if you already provided a value yourself
(otherwise you will first have to test if :NEW.<column name> is null, but I wouldn't do this for a key column.
if you need the generated key back for further processing (inserting it into a child table for example), you can use the returning clause on the insert statement
see the oracle documentation for more information about sequences, triggers and the returning clause
greetings
Freek D
I am new to Oracle and need to know how to create a table that uses an automatic incrementation on a primay key for it's default. I need the uniqueness automatically managed by the DBMS.. This activity is know as setting the Column (primary key with identity) in Ms-SQL..
Your help would be appreciated greatly....
Thanks.... -
CMP entity bean with compound primary key
I'm trying to use a compound primary key in a CMP entity bean. I've created the custom primary key class okay, and I have the prim-key-class set in ejb-jar.xml. My client app gets the home reference okay, but when it tries to find an entity, I get the exception "SQLException: Incorrect syntax near '/'."
I think I'm having trouble deploying this in OC4J. Is there a sample orion-ejb-jar.xml deployment for a custom, compound primary key somewhere?
Many thanks for any help.
ErnieNever mind. I solved my problem. Thanks.
-
Problem with inserting into table that has autogenerated primary key
hi
i am working on EJB3.
i am trying to insert object into table.Primary key of table will be generated automatically.I tried following statement for insertion,
em.persistent(customerObj);
but it throw following exception,
javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): customer.CustomerInfo
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:211)
at org.jboss.ejb3.stateless.Stateles
can anyone tell me is there any other way to acheive the same.
i thought of doing using insert query,but i am not sure about the syntax to be used.
could anyone help me ?
thanks in advance...That's why you should use PreparedStatement instead of Statement. Its setString() method will escape that value for you properly when you bind it.
% -
Unable to create new entry in table that has no primary key
Hi
I have a table which is required to have no primary key (except mandt). After i generate table maintanance, when I go to create new entries, the table control to enter the new values does not appear. When I click on edit->new entries, it goes back to the fields tab of the table. Same when i check through SM30.
If i maintain atleast one primary key, I am able to get the table control in new entries screen. However the requirement permits no primary keys except mandt. How can this be resolved?
Thanks
NMHi,
THE PROBLEM WITH UR TABLE IS
YOU HAD DECLARED MANDT AS THE PRIMARY KEY AND THERE IS NO OTHER KEY IN UR TABLE
iT'S NOT ALLOWING YOU TO ADD NEW ENTRIES BECAUSE MANDT IS THE ONLY PRIMARY KEY IN YOUR TABLE AND IT WILL HAVE A DEFAULT VALUE BASED ON THE CLIENT. SO IT'S NOT SHOWING YOU THE CREATE NEW ENTRIES OPTION.
SO TRY TO PUT ONE MORE FIELD AS THE PRIMARY KEY SO THAT YOUR PROBLEM WILL SOLVE VERY EASILY ALSO MAKE SURE THAT TABLE IS ACTIVATED.
REVERT IF U NEED SOME MORE HELP
Thanks &Regards.
Pavan. -
Can we create an APEX Form based on Table which has no Primary Key
Hi,
I have a requirement.
I need to create a FORM based on a table having no Primary Key but it is having Unique Key . I can use Unique Key as an alternate of Primary Key.
but When I tried to create a Form, I got the following message.
Source tables for forms and tabular forms must have a primary key
Thanks,
DeepakDeepak_J wrote:
Hi,
I have a requirement.
I need to create a FORM based on a table having no Primary Key but it is having Unique Key . I can use Unique Key as an alternate of Primary Key.
but When I tried to create a Form, I got the following message.
Source tables for forms and tabular forms must have a primary key
Thanks,
DeepakGood database design will always require a PK on the tables. There are only very few and rare expetions to this rule. One would be when you have store the data only temporarily in this table, like it is often done for import/loader tables. The data is first loaded in the "import"-table, then validated and then transported to the "real" tables. In such a scenario you can ignore the primary key on purpose. Because you already have a UK on this table it can't be such a scenario.
For most other scenarios you should always add a PK. Ask critically why there is no PK on it. Is there a reason for it or was the table designer just not doing its job well?
Btw: A UK is identical to a PK if the column is mandatory (NOT NULL). In this case you could simply change the constraint from UK to PK. -
Entity Object with Nullabl Primary Key Parts
I posted an article on how to handle nullable PKs.
Here is the link:
http://radio.weblogs.com/0123729/stories/2003/05/15/entityObjectOverTableWhosePrimaryKeyMayBeNull.html
Please take a look if you're interested in the topic.Most likely the record in the database has an extra white space attached to it.
For ex:- 'Harry ' instead of 'Harry';
If you have an extra space there then findByPrimaryKey("Harry") will not be find that record.
You can test it launching a SQL*PLUS
and
select col from table
where col='Harry'
this would return "no rows found" if it has an extra white space.
raghu -
USE ROWID AS PRIMARY KEY OF ENTITY ON EJB3
When we launch the Create Entities from Tables wizard, and create JPA (Java Persistence API) entities from existing database tables, if the table has no primary key and unique key field, you will get a warning. When you run, you will get the following information:
Caused by: Exception [TOPLINK-7161] (Oracle TopLink Essentials - 2006.8 (Build 060829)): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: Entity class [class model.Test] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass.
Actually, every row of oracle table has a ROWID field , I think it is a good “primary key field”. Add it into Entity Java bean file as following:
@Id
private ROWID rowid;
And generate accessors, ok, run……
GOOD, No problem.
But when you insert a new row, got an exception:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.8 (Build 060829)): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00928: missing SELECT keyword
Error Code: 928
Call:INSERT INTO TEST (ROWID, B, A) VALUES (?, ?, ?)
bind => [null, 555, 555]
Query:InsertObjectQuery(model.Test@40979b)
555~~~, what happened?! Somebody builds a wrong SQL …
Don’t worry! I know (…) where is the “bug”.
Find out the class
oracle.toplink.essentials.internal.expressions. SQLInsertStatement
which is included in the toplink-essentials.jar,
decompile… , fix…, compile, and jar it back.
Fix
if(field.getTable().equals(getTable()) || !field.hasTableName())
to
if((field.getTable().equals(getTable()) || !field.hasTableName()) && !field.getName().equalsIgnoreCase("ROWID"))
OK, it is running well.
I suggest ORACLE fix it into his next version. Do you think it is a good idea?Do you think it is a good idea? Not really, but that's just my two cents.
-
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 -
Can EJB 3.0 beans be used with tables that do not have a primary key?
Can a EJB 3.0 persistence bean be used with tables that do not have a primary key defined? I am building a test application based on the HowTo - Building EJB 3.0 Faces App paper posted after Openworld (schalk). The issue I am running into when trying to run the application is: Exception Description: Entity class [class com.persistence.Rpthead] has no primary key specified. Note: I get a simular error when using toplink directly.
The tables I am binding to do not have primary keys defined. They use unique constraints to manage the table integrity.
Is it possible to use EJB 3.0 on tables without a primary key? If not, are there plans to support this in the future?The spec requires a primary key Id annotation. I will take your suggestion to EJB 3.0 expert group.
Can you also send an email to [email protected] with your requirement?
-Debu
Maybe you are looking for
-
I get this error message when I save some files "sty is null"
When I try to save some files I get an error message that says Unable to initialize the UI, sty is null. It happens mostly when saving files to an Aaptorefromtdotnet e commerce web site. If I click OK either it file saves or I get a second error mess
-
I'm configuring our ASA and we have two AT&T circuits which we're only using one with our current Juniper firewall. I know the ASA doesn't support policy based routing so I'm wondering if the following hypothetical "config" is possible. External Inte
-
I installed the Puzzle 0.4.6 add-on which is supposed to add the "Puzzle" item to the main context menu, but when right clicking a picture it does not give the option to open with the puzzle add-on.
-
When I build my iPhone app using the simulator I have no errors and it works great, but when I build for the device I'm having link errors because it's not finding several of the netinet headers. The files in particular that are missing: #include <ne
-
Does anyone have a reference to the different screen sequence groups for Sales Document Types and how they are different from each other? I want to set my Text Determination for my Quantity Contracts to allow the Text in overview screen, but I get m