Jpa2.0 is integrated with spring, and the persistence. xml file can be required or not.
For persistence. XML, you only need to make the following simple configuration:
<? 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 = "App" Transaction-type = "Resource_local" /> </ Persistence >
The spring configuration is as follows:
<! -- Data Source --> < Bean ID = "Datasource" Class = "Com. jolbox. bonecp. bonecpdatasource" Destroy-Method = "Close" > <! -- Database-driven --> < Property Name = "Driverclass" Value = "$ {JDBC. driverclassname }" /> <! -- Jdbcurl of the driver --> < Property Name = "Jdbcurl" Value = "$ {JDBC. url }" /> <! -- Database username --> < Property Name = "Username" Value = "$ {JDBC. Username }" /> <! -- Database Password --> < Property Name = "Password" Value = "$ {JDBC. Password }" /> <! -- Check the idle connection interval in the database connection pool. Unit: minute. Default Value: 240. If you want to cancel the interval, set it to 0. --> < Property Name = "Idleconnectiontestperiod" Value = "$ {Bonecp. idleconnectiontestperiod }" /> <! -- Maximum Lifetime of unused connections in the connection pool. Unit: minute. Default Value: 60. If you want to survive forever, set it to 0. --> < Property Name = "Idlemaxage" Value = "$ {Bonecp. idlemaxage }" /> <! -- Maximum number of connections per Partition --> < Property Name = "Maxconnectionsperpartition" Value = "$ {Bonecp. maxconnectionsperpartition }" /> <! -- Minimum number of connections per Partition --> < Property Name = "Minconnectionsperpartition" Value = "$ {Bonecp. minconnectionsperpartition }" /> <! -- Number of partitions. The default value is 2. The minimum value is 1. The recommended value is 3-4, depending on the application. --> < Property Name = "Partitioncount" Value = "$ {Bonecp. partitioncount }" /> <! -- Each time you connect to a database, you need to get a few at a time. The default value is 2. --> < Property Name = "Acquireincrement" Value = "$ {Bonecp. acquireincrement }" /> <! -- Cache prepared statements size. Default Value: 0 --> < Property Name = "Statementscachesize" Value = "$ {Bonecp. statementscachesize }" /> <! -- The number of Assistant processes that are released in each partition. The default value is 3. Too many assistant processes will affect your performance unless you have done a lot of work during the connection time of a database. --> < Property Name = "Releasehelperthreads" Value = "$ {Bonecp. releasehelperthreads }" /> </ Bean > <! -- JPA Entity Manager Factory --> < Bean ID = "Entitymanagerfactory" Class = "Org. springframework. Orm. JPA. localcontainerentitymanagerfactorybean" > < Property Name = "Datasource" Ref = "Datasource" /> < Property Name = "Persistenceprovider" Ref = "Persistenceprovider" /> < Property Name = "Jpavendoradapter" Ref = "Jpavendoradapter" /> < Property Name = "Jpadialect" Ref = "Jpadialect" /> < Property Name = "Packagestoscan" Value = "Cn. luxh. App. Entity" /> < Property Name = "Jpaproperties" > < Props > < Prop Key = "Hibernate. dialect" > Org. hibernate. dialect. mysql5dialect </ Prop > < Prop Key = "Hibernate. Connection. driver_class" > Com. MySQL. JDBC. Driver </ Prop > < Prop Key = "Hibernate. max_fetch_depth" > 3 </ Prop > < Prop Key = "Hibernate. JDBC. fetch_size" > 18 </ Prop > < Prop Key = "Hibernate. JDBC. batch_size" > 10 </ Prop > < Prop Key = "Hibernate. hbm2ddl. Auto" > Update </ Prop > < Prop Key = "Hibernate. show_ SQL" > True </ Prop > < Prop Key = "Hibernate. format_ SQL" > True </ Prop > < Prop Key = "Javax. Persistence. validation. mode" > None </ Prop > </ Props > </ Property > </ Bean > <! -- Used to specify the persistence implementation factory class --> < Bean ID = "Persistenceprovider" Class = "Org. hibernate. EJB. hibernatepersistence" /> <! -- Used to set specific attributes of the JPA implementation vendor --> < Bean ID = "Jpavendoradapter" Class = "Org. springframework. Orm. JPA. Vendor. hibernatejpavendoradapter" > < Property Name = "Database" Value = "MySQL" /> </ Bean > <! -- Used to specify some advanced features --> < Bean ID = "Jpadialect" Class = "Org. springframework. Orm. JPA. Vendor. hibernatejpadialect" /> <! -- Transaction Manager --> < Bean ID = "Txmanager" Class = "Org. springframework. Orm. JPA. jpatransactionmanager" > < Property Name = "Entitymanagerfactory" Ref = "Entitymanagerfactory" /> </ Bean >
This should be a good integration between jpa2.0 and spring.
If you do not need the persistence. xml file, delete it.