2012-09-25 44 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不是实现,而只是持久性应该如何定义。

相关问题