Bonjour à tous.
Je me fais une application Spring 5 et JPA 2 qui fonctionne très bien pour l'instant.
Actuellement ma configuration JPA est dans le fichier persitence.xml et Spring dans son propre fichier.
J'ai configuré ma datasource dans Spring car j'utilise son transaction manager.
Important : je n'utilise ni spring boot, ni une configuration de spring en java, ni ne souhaite passer par le framework Spring JPA car le but est surtout de me (re)familiariser avec les requêtes JPQL et les criterias
J'ai cherché dans les doc Spring et je ne trouve pas du tout comment je peux faire pour me passer du fichier persistence.xml bien que cette fonctionnalité était offerte avec les anciennes version de Spring.
Alors voila si quelqu'un peu me conseiller des ressources actualisées pour cette version de Spring ou me dire comment faire, je lui en serai très reconnaissant.
Je vous joins également mes fichiers de persistence et spring
persistence.xml
Fichier de properties Spring
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 <?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="persistenceUnitTest" transaction-type="RESOURCE_LOCAL"> <description> Persistence unit for the JPA tutorial of the Hibernate Getting Started Guide </description> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <class>com.entities.Configuration</class> <class>com.entities.ConfigurationCategory</class> <class>com.entities.Profile</class> <class>com.entities.ProfileCategory</class> <class>com.entities.Right</class> <class>com.entities.RightCategory</class> <class>com.entities.UserAccount</class> <properties> <property name="javax.persistence.schema-generation.database.action" value="create"/> <property name="javax.persistence.sql-load-script-source" value="sql/db-insert.sql"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.hbm2ddl.auto" value="create"/> </properties> </persistence-unit> </persistence>
Fichier Spring
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5javax.persistence.jdbc.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE javax.persistence.jdbc.driver=org.h2.Driver javax.persistence.jdbc.user=sa javax.persistence.jdbc.password=
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 <?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" xmlns:jdbc="http://www.springframework.org/schema/jdbc" 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 http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> <context:annotation-config/> <context:component-scan base-package="com" /> <context:property-placeholder location="jpa.properties"/> <bean id="dataSourceTest" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${javax.persistence.jdbc.driver}"/> <property name="url" value="${javax.persistence.jdbc.url}"/> <property name="username" value="${javax.persistence.jdbc.user}"/> <property name="password" value="${javax.persistence.jdbc.password}"/> </bean> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSourceTest"/> <property name="persistenceUnitName" value="persistenceUnitTest"/> </bean> <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/> <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="dataSource" ref="dataSourceTest"/> </bean> </beans>
Partager