Why does Hibernate ignore the standardized JPA2 properties in my persistence.xml?

I have a very simple web application running on Tomcat using Spring 3.0.2, Hibernate 3.5.1, JPA 2, and Derby. I am defining all the capabilities of my database in persistence.xmland just using Spring to inject dependencies. I use the built-in Derby as my database.

Everything works correctly when I define the properties of the driver and the URL persistence.xmlin Hibernate classic mode this way:

<property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="hibernate.connection.url" value="jdbc:derby:webdb;create=true"/>

Problems arise when switching my configuration to the standardized JPA2 properties as follows:

<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:webdb;create=true"/>

Using JPA2 property keys, the application requires a lot of effort with the following exception:

java.lang.UnsupportedOperationException: The user must supply a JDBC connection

Does anyone know why this fails?

. javax... Hibernate, .

+3
4

, Spring, , LocalContainerEntityManagerFactoryBean. Spring, @PersistenceContext, EntityManager Java SE. @PersistenceContext Persistence.createEntityManagerFactory("WebApp").createEntityManager(); ( EntityManager Spring), , .

, Spring, :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:component-scan base-package="net.webapp"/>
    <tx:annotation-driven/>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
</beans>
+3

( Spring, ). persistence.xml, :

<?xml version="1.0" encoding="UTF-8"?>
<persistence
    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"
    version="2.0">

  <persistence-unit name="PetstorePu" transaction-type="RESOURCE_LOCAL">

    <properties>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby:webdb;create=true"/>

      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>

maven , :

<!-- JPA2 provider -->
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-entitymanager</artifactId>
  <version>3.5.1-Final</version>
</dependency>
<!-- Logging -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.5.10</version>
</dependency>
<!-- JDBC driver -->
<dependency>
  <groupId>org.apache.derby</groupId>
  <artifactId>derby</artifactId>
  <version>10.5.3.0_1</version>
</dependency>

classpath :

alt text

+2

Maven eclipse, jar classpath 3.5

1) ​​

2) hibernate annotations jar

3) jboss logging jar

4) jibernate entity manager jar

JPA API 2. jar ( ).

, , . . - ,

+2

, , . , . , . , . Hibernate PostgreSQL

,

   <provider>org.hibernate.ejb.HibernatePersistence</provider>

persistence.xml

   <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
   <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/reverseepg-foxtel"/>
   <property name="hibernate.connection.username" value="postgres"/>
   <property name="hibernate.connection.password" value="password"/>

   If I provide below properties it doesn't work

   <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
   <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/reverseepg-foxtel"/>
   <property name="javax.persistence.jdbc.user" value="postgres"/>
   <property name="javax.persistence.jdbc.password" value="password"/>
+1

Source: https://habr.com/ru/post/1741618/


All Articles