aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Why i am getting no primary key specified exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Why i am getting no primary key specified exception?" Watch "Why i am getting no primary key specified exception?" New topic
Author

Why i am getting no primary key specified exception?

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Even though i have added a primary key to my class Car.java, but still it is giving a primary key exception.

Car.java
-------------
package Pack;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Car")
public class Car {



@Id
@Column(name="id")
private static Long id;
@Column(name="horn")
private static String horn;
@Column(name="steering")
private static String steering;
@Column(name="wheel")
private static String wheel;


public Car(){

}

}
---------------------------

my Server.log file

-----------------------
[#|2008-11-24T16:09:07.843-0500|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.tools.deployment|_ThreadID=12;_ThreadName=Timer-2;_RequestID=6fb25190-b619-4490-9e84-2895bfcbe10e;|Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: Deployment Error --
Exception Description: Entity class [class Pack.Car] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass.
at oracle.toplink.essentials.exceptions.ValidationException.noPrimaryKeyAnnotationsFound(ValidationException.java:1112)
at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataValidator.throwNoPrimaryKeyAnnotationsFound(MetadataValidator.java:210)
at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessor.validatePrimaryKey(ClassAccessor.java:1470)
at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessor.process(ClassAccessor.java:463)
at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor.processAnnotations(MetadataProcessor.java:196)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.processORMetadata(EntityManagerSetupImpl.java:993)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:501)
at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactoryProvider.java:152)
at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.loadPersistenceUnitBundle(PersistenceProcessor.java:467)
at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.createTablesInDB(PersistenceProcessor.java:325)
at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.processAppBundle(PersistenceProcessor.java:190)
at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.processApplication(PersistenceProcessor.java:125)
at com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processApplication(DeploymentEventListenerImpl.java:193)
at com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processEvent(DeploymentEventListenerImpl.java:152)
at com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.notifyDeploymentEvent(DeploymentEventListenerImpl.java:109)
at com.sun.enterprise.deployment.backend.DeploymentEventManager.notifyDeploymentEvent(DeploymentEventManager.java:66)
at com.sun.enterprise.deployment.backend.ModuleDeployer.handlePostDeployEvent(ModuleDeployer.java:689)
at com.sun.enterprise.deployment.backend.ModuleDeployer.postDeploy(ModuleDeployer.java:677)
at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:169)
at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:169)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:263)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:281)
at com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.deploy(ApplicationsConfigMBean.java:534)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:353)
at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:336)
at com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:448)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:77)
at $Proxy1.invoke(Unknown Source)
at com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:297)
at com.sun.enterprise.deployment.autodeploy.AutoDeployer.invokeDeploymentService(AutoDeployer.java:413)
at com.sun.enterprise.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:394)
at com.sun.enterprise.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:253)
at com.sun.enterprise.deployment.autodeploy.AutoDeployControllerImpl$AutoDeployTask.run(AutoDeployControllerImpl.java:358)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
|#]

[#|2008-11-24T16:09:07.843-0500|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.tools.deployment|_ThreadID=12;_ThreadName=Timer-2;Deployment Error --
Exception Description: Entity class [class Pack.Car] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass.
;_RequestID=6fb25190-b619-4490-9e84-2895bfcbe10e;|"DPL8011: autodeployment failure while deploying the application : Deployment Error --
Exception Description: Entity class [class Pack.Car] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass.
"|#]

[#|2008-11-24T16:09:07.843-0500|INFO|sun-appserver-pe9.0|javax.enterprise.system.tools.deployment|_ThreadID=12;_ThreadName=Timer-2;|[AutoDeploy] Autodeploy failed : C:\Sun\SDK\domains\domain1\autodeploy\JarFile.jar.|#]

---------------------------

Can anybody let me know, why it is not detecing the @Id annotation im my class.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Oh i forget to implement Serializable, i did this, but the problem exists.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
i solved the above problem by modifying the below class-

package Pack;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Car")
public class Car implements Serializable{



@Id
@Column(name="id")
protected Long id;
@Column(name="horn")
protected String horn;
@Column(name="steering")
protected String steering;
@Column(name="wheel")
protected String wheel;


public Car(){

}

}
Meherdad Bomanbehram
Ranch Hand

Joined: May 28, 2007
Posts: 130

Hi Amandeep Singh,
To me it just seems that since your Car class had no non-private members and if you have all private members than you must have non-private acessor methods else how will anyone update the entity.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
yes i got it.
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Serializable is not must.
 
 
subject: Why i am getting no primary key specified exception?
 
Similar Threads
JNDI Problem...
JNDI Problem...
the hello-jaxws sample
Table per class Support in JPA
wsdl file WEB-INF/wsdl/wscoor.wsdl does not exist