Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify JPA 2.1 in persistence.xml?

A quick search on the Net reveals three or four variants how folks have been specifying xmlns and xsi:schemaLocation in persistence.xml.

What would be the 'correct' manner to specify JPA version 2.1?

I'm using

<persistence version="2.1"              xmlns="http://xmlns.jcp.org/xml/ns/persistence"              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence              http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> 
like image 728
kmansoor Avatar asked Jan 15 '14 15:01

kmansoor


People also ask

What is persistence xml in JPA?

The persistence. xml file is a standard configuration file in JPA. It has to be included in the META-INF directory inside the JAR file that contains the entity beans. The persistence.

How do I update JPA version?

Right-click the file and click Upgrade document version. The persistence. xml file is upgraded to either version 2.0 or 2.1. Confirm the upgrade by opening the file in the Persistence XML editor and check that the version that displays is the one that you want.

Does Spring data JPA require persistence xml?

persistence. xml is needed when you're using Hibernate through JPA, even though you're using Spring JPA. If you're using Hibernate directly, then persistence. xml isn't needed.


1 Answers

According to the official documentation it must be (like yours):

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence              http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"              version="2.1">     ... </persistence> 
like image 107
V G Avatar answered Oct 06 '22 01:10

V G