EJB中entityBean

用jdeveloper 開發 ejb時,的確很方便.但是,在創建entitybean時,一定要注意一點,這點是我經常犯的錯誤.說明如下:

開發工具 jdeveloper
數據庫 Oracle
創建數據庫腳本 
create table myinfo(
    usernum varchar2(20),
    username varchar2(20)
)

我們用這段腳本創建好數據庫,並生成實體bean.
下一步我們將entitybean部署,但是他會jdeveloper 會拋出這樣的異常

//////////////////////////異常/////////////////////////////////////////////////////////////////////
[EJB 3.0]: Assigning default-data-source=jdbc/tonywolfDS, specified in projects EJB 3.0 properties
[Starting OC4J using the following ports: HTTP=8990, RMI=23893, JMS=9229.]
F:/jdevstudio10132/jdev/system/oracle.j2ee.10.1.3.40.66/embedded-oc4j/config>
F:/jdevstudio10132/jdk/bin/javaw.exe -client -classpath F:/jdevstudio10132/j2ee/home/oc4j.jar;F:/jdevstudio10132/jdev/lib/jdev-oc4j-embedded.jar -Xverify:none -XX:MaxPermSize=256m -DcheckForUpdates=adminClientOnly -Doracle.application.environment=development -Doracle.j2ee.dont.use.memory.archive=true -Doracle.j2ee.http.socket.timeout=500 -Doc4j.jms.usePersistenceLockFiles=false oracle.oc4j.loader.boot.BootStrap -config F:/jdevstudio10132/jdev/system/oracle.j2ee.10.1.3.40.66/embedded-oc4j/config/server.xml
[waiting for the server to complete its initialization...]
2009-5-9 9:22:26 com.evermind.server.jms.JMSMessages log
信息: JMSServer[]: OC4J JMS server recovering transactions (commit 0) (rollback 0) (prepared 0).
2009-5-9 9:22:26 com.evermind.server.jms.JMSMessages log
信息: JMSServer[]: OC4J JMS server recovering local transactions Queue[jms/Oc4jJmsExceptionQueue].
[TopLink Config]: 2009.05.09 09:22:28.703--ServerSession(31528250)--The alias name for the entity class [class project1.Bonus] is being defaulted to: Bonus.
[TopLink Config]: 2009.05.09 09:22:28.875--ServerSession(31528250)--The table name for entity [class project1.Bonus] is being defaulted to: BONUS.
[TopLink Config]: 2009.05.09 09:22:28.875--ServerSession(31528250)--The column name for element [public java.lang.Long project1.Bonus.getSal()] is being defaulted to: SAL.
[TopLink Config]: 2009.05.09 09:22:28.890--ServerSession(31528250)--The column name for element [public java.lang.String project1.Bonus.getJob()] is being defaulted to: JOB.
[TopLink Config]: 2009.05.09 09:22:28.890--ServerSession(31528250)--The column name for element [public java.lang.String project1.Bonus.getEname()] is being defaulted to: ENAME.
[TopLink Config]: 2009.05.09 09:22:28.890--ServerSession(31528250)--The column name for element [public java.lang.Long project1.Bonus.getComm()] is being defaulted to: COMM.
2009-5-9 9:22:28 com.evermind.server.ejb.logging.EJBMessages logException
嚴重: [current-workspace-app] 部署 EJB 模塊時出錯: com.evermind.server.ejb.exception.DeploymentException: [current-workspace-app:Application2_Project1_0] - 使用 PersistenceProvider 類 oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider 爲持久性單元 Project1 創建 EntityManagerFactory 時出現異常錯誤。
com.evermind.server.ejb.exception.DeploymentException: [current-workspace-app:Application2_Project1_0] - 使用 PersistenceProvider 類 oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider 爲持久性單元 Project1 創建 EntityManagerFactory 時出現異常錯誤。
    at com.evermind.server.ejb.exception.DeploymentException.exceptionCreatingEntityManagerFactory(DeploymentException.java:130)
    at com.evermind.server.ejb.persistence.PersistenceUnitManagerImpl.createContainerEntityManagerFactory(PersistenceUnitManagerImpl.java:197)
    at com.evermind.server.ejb.persistence.PersistenceUnitManagerImpl.initializePersistenceUnit(PersistenceUnitManagerImpl.java:159)
    at com.evermind.server.ejb.persistence.PersistenceUnitManagerImpl.initialize(PersistenceUnitManagerImpl.java:86)
    at com.evermind.server.ejb.EJBPackageDeployment.initializePersistenceUnitManager(EJBPackageDeployment.java:1022)
    at com.evermind.server.ejb.EJBContainer.postInit(EJBContainer.java:845)
    at com.evermind.server.ApplicationStateRunning.initializeApplication(ApplicationStateRunning.java:217)
    at com.evermind.server.Application.setConfig(Application.java:439)
    at com.evermind.server.Application.setConfig(Application.java:340)
    at com.evermind.server.ApplicationServer.addApplication(ApplicationServer.java:1853)
    at com.evermind.server.ApplicationServer.initializeDeployedApplications(ApplicationServer.java:1608)
    at com.evermind.server.ApplicationServer.setConfig(ApplicationServer.java:990)
    at com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLauncher.java:131)
    at java.lang.Thread.run(Thread.java:595)
Caused by: Exception [TOPLINK-7161] (Oracle TopLink Essentials - 2006.8 (Build 060829)): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: Entity class [class project1.Bonus] 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.evermind.server.ejb.persistence.PersistenceUnitManagerImpl.createContainerEntityManagerFactory(PersistenceUnitManagerImpl.java:192)
    ... 12 more
09/05/09 09:22:28 警告: Application.setConfig Application: current-workspace-app is in failed state as initialization failed.
java.lang.InstantiationException: Error initializing ejb-modules: [current-workspace-app:Application2_Project1_0] - 使用 PersistenceProvider 類 oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider 爲持久性單元 Project1 創建 EntityManagerFactory 時出現異常錯誤。
2009-5-9 9:22:28 com.evermind.server.ServerMessages warningApplicationInitializationFailed
警告: 初始化已部署的應用程序時出現異常錯誤: current-workspace-app。Application: current-workspace-app is in failed state as initialization failed
Ready message received from Oc4jNotifier.
Embedded OC4J startup time: 7187 ms.
09/05/09 09:22:30 Oracle Containers for J2EE 10g (10.1.3.1.1)  initialized

//////////////////////////////////////////////////////////////////////////////////////////////////
原因,因爲我們在部署entitybean的時候需要有主件的支持,但是剛纔的sql腳本里卻不含主鍵,因此,會拋出這樣的異常.
解決辦法,設置主鍵即可


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章