昨天試了一下把mysql的資料來源配置mysql-ds.xml放在jboss下面跑,成功了;後來我想那oracle資料來源配置oracle-ds.xml也可以在jboss下面跑了。我就試了一下, 在啟動Eclipse時報以下錯誤:
11:04:48,078 INFO [SettingsFactory] JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0
11:04:48,125 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=#ztf state=Create
javax.persistence.PersistenceException: [PersistenceUnit: ztf] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)
at org.jboss.jpa.deployment.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:311)
Caused by: org.hibernate.HibernateException: unknown Oracle major version [0]
at org.hibernate.dialect.DialectFactory$1.getDialectClass(DialectFactory.java:173)
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:88)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:62)
11:04:48,265 ERROR [ProfileServiceBootstrap] Failed to load profile: Summary of incomplete deployments (SEE PREVIOUS ERRORS
FOR DETAILS):
*** CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}
jboss.j2ee:jar=EntityBean.jar,name=PersonServiceBean,service=EJB3
-> <UNKNOWN jboss.j2ee:jar=EntityBean.jar,name=PersonServiceBean,service=EJB3>{Described:** UNRESOLVED Demands
'persistence.unit:unitName=#ztf' **}
*** CONTEXTS IN ERROR: Name -> Error
persistence.unit:unitName=#ztf -> org.hibernate.HibernateException: unknown Oracle major version [0]
<UNKNOWN jboss.j2ee:jar=EntityBean.jar,name=PersonServiceBean,service=EJB3> -> ** UNRESOLVED Demands
'persistence.unit:unitName=#ztf' **
11:04:48,453 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8090
出現這個問題,接著在網上google了一下,在http://forum.hibernate.org/viewtopic.php?p=2373597下找到了答案。
我出現的問題已解決,如下:
1.persistence.xml下<jta-data-source>的資料來源配置為java:/ztfDS。
2.在persistence.xml下<properties>加入SQL方言<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
jboss下資料來源的配置,分以下幾種情況:
1.選擇的是mysql-ds.xml,此檔案相應位置設為 <jndi-name>ztfDS</jndi-name>,那麼在persistence.xml中相應設定為<jta-data-source>java:ztfDS</jta-data-source>。
2.選擇的是oracle-ds.xml,此檔案相應位置設為<jndi-name>ztfDS</jndi-name>,那麼在persistence.xml中相應設定為<jta-data-source>java:/ztfDS</jta-data-source>。