Thread: JPA annotations with persistence.xml

Forum : Hibernate Core and Annotations.   8 Jan, 2019 19:14
User Image


Joined: 5 Oct, 2018

Points: 100

Threads: 3

Posts: 6

Answer Icon JPA annotations with persistence.xml

| Quote Date : 8 Jan, 2019    Views:480    

Anyone please tell me.  If we use JPA annotaions with Hibernate as implementation, we can represent the entity classes in  hibernate.cfg.xml  as <mapping class=" "/>

But if I want to write persistence.xml , then how can I represent the entity class in persistence.xml.


User Image


Joined : 14 Oct, 2018

Points : 100

Threads: 0

Posts: 1

Re: JPA annotations with persistence.xml

Reply Date : 12 Jan, 2019

First, you have to create orm.xml file then you can configure this file in persistent.xml.

<mapping-file>packagename/orm.xml file</mapping-file>

User Image


Joined : 15 Jul, 2016

Points : 1020

Threads: 645

Posts: 207

Answer IconRe: JPA annotations with persistence.xml

Reply Date : 9 Jan, 2019

Here is how your persistence.xml should be written.

<persistence-unit name="demounit" transaction-type="RESOURCE_LOCAL">
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpa" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="root" />          

Load More

No More Comments