用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脚本里却不含主键,因此,会抛出这样的异常.
解决办法, 设置主键即可
开发工具 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脚本里却不含主键,因此,会抛出这样的异常.
解决办法, 设置主键即可