2012-09-25 43 views
0

早期我使用JPA爲我的應用程序開發了ORM。在peristenc.xml中,我定義了hibernate provider並使用非JTA-DataSource。 JPA可以在沒有休眠提供程序的情況下運行。那麼我省略了persistence.xml中的hibernate代碼。然後我部署了,在控制檯中我收到以下信息。JPA可以在沒有休眠提供程序的情況下運行。

18:19:56,028 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-6) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider 
    18:19:56,032 INFO [org.hibernate.dialect.Dialect] (MSC service thread 1-6) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect 
    18:19:56,033 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-6) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactor 

但我沒有提到在我的應用程序中關於休眠的地方。

** 的persistence.xml ** *

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.0" 
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
    <persistence-unit name="StudentManagementSystem" transaction-type="RESOURCE_LOCAL"> 
     <non-jta-data-source>java:jboss/datasources/studentDS</non-jta-data-source> 
     <class>com.dms.entity.student.StudentDetail</class> 
     <class>com.dms.entity.student.MarkDetail</class> 
     <class>com.dms.entity.student.PRDSemesterDetail</class> 
     <class>com.dms.entity.admin.LoginDetail</class> 
    </persistence-unit> 
</persistence> 

*非JTA-數據源*

<datasource jndi-name="java:jboss/datasources/studentDS" pool-name="studentDS" enabled="true" use-java-context="true"> 
        <connection-url>jdbc:mysql://localhost:3306/exercise</connection-url> 
        <driver>com.mysql</driver> 
        <security> 
         <user-name>student</user-name> 
         <password>student</password> 
        </security> 
       </datasource> 
<driver name="com.mysql" module="com.mysql"> 
         <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlDataSource</xa-datasource-class> 
        </driver> 

回答

2

你正在運行你的應用程序在JBoss中,而Hibernate是JBoss的默認持久性提供者。正如規範所述,持久性提供者在persistence.xml中是可選的。在這種情況下,容器(JBoss)使用其默認提供程序。

1

是的,你可以,你可以指定要使用這把你的persistence.xml其中JPA提供商:

<persistence-unit name="default" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
    ... 
</persistence-unit> 

的例子使用Eclipse的鏈接作爲供應商。你必須在你的類路徑中有供應商特定的jar才能工作(eclipse-link,openJPA,hibernate,iBatis等)

你得到的消息是因爲你的服務器已經有一個捆綁了它的hibernate實現,這是默認的,但你應該能夠通過設置正確的提供者來使用你想要的實現。

但是,如果不提供任何提供程序,您將無法運行JPA,因爲JPA不是實現,而只是持久性應該如何定義。

相關問題