Thread: JPA annotations wth persistence.xml

Forum : Hibernate Core and Annotations.   9 Days ago
User Image
Bhargava

Newbie

Joined: 5 Oct, 2018

Points: 100

Threads: 3

Posts: 4

Answer Icon JPA annotations wth persistence.xml

| Quote Date : 8 Jan, 2019    Views:198    

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.

Comments

User Image
Shubhendu

Newbie

Joined : 14 Oct, 2018

Points : 100

Threads: 0

Posts: 1

Re: JPA annotations wth 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
Sriman

Member

Joined : 15 Jul, 2016

Points : 1000

Threads: 645

Posts: 201

Answer IconRe: JPA annotations wth persistence.xml

Reply Date : 9 Jan, 2019

Here is how your persistence.xml should be written.



<persistence-unit name="demounit" transaction-type="RESOURCE_LOCAL">
    <class>com.jcg.jpa.demo.Farmer</class>      
    <properties>
        <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" />          
    </properties>
</persistence-unit>



Load More

No More Comments