I want to use orm.xml along with persistence.xml but it is not working and throwing me the exception as ' Duplicate XML entry for hello.Message' , Message is my annotated class.
my persistence.xml is as described below -<persistence 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/ ... ce_1_0.xsd"
version="1.0">
<persistence-unit name="helloworld">
<!-- The provider only needs to be set if you use several JPA providers
<provider>org.hibernate.ejb.HibernatePersistence</provider>
-->
<!-- This is required to be spec compliant, Hibernate however supports
auto-detection even in JSE.
<class>hello.Message</class>
-->
<properties>
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<!-- SQL stdout logging
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="use_sql_comments" value="true"/>
-->
<property name="hibernate.connection.driver_class"
value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.connection.url"
value="jdbc:hsqldb:hsql://localhost"/>
<property name="hibernate.connection.username"
value="sa"/>
<property name="hibernate.c3p0.min_size"
value="5"/>
<property name="hibernate.c3p0.max_size"
value="20"/>
<property name="hibernate.c3p0.timeout"
value="300"/>
<property name="hibernate.c3p0.max_statements"
value="50"/>
<property name="hibernate.c3p0.idle_test_period"
value="3000"/>
<property name="hibernate.dialect"
value="org.hibernate.dialect.HSQLDialect"/>
</properties>
</persistence-unit>
</persistence>
and ORM.xml is as described below --<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
xmlns = "http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
version ="1.0">
<entity class="hello.Message" access="FIELD">
<table name="MESSAGES"/>
<attributes>
<basic name = "fistName" >
<column name="FIRST_NAME"/>
</basic>
</attributes>
</entity>
</entity-mappings>
Message is my annotated class as described below --package hello;
import javax.persistence.*;
@Entity
@Table(name = "MESSAGES")
public class Message {
@Id @GeneratedValue
@Column(name = "MESSAGE_ID")
private Long id;
@Column(name = "MESSAGE_TEXT")
private String text;
@Column(name = "FIRST_NAME")
private String fistName;
public String getFistName() {
return fistName;
}
public void setFistName(String fistName) {
this.fistName = fistName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Column(name = "LAST_NAME")
private String lastName;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "NEXT_MESSAGE_ID")
private Message nextMessage;
Message() {}
public Message(String text) {
this.text = text;
}
public Message(String text,String firstName,String lastName) {
this.text = text;
this.fistName = firstName;
this.lastName = lastName;
}
public Long getId() {
return id;
}
private void setId(Long id) {
this.id = id;
}
public String getText() {
return text;
}
public final void setText(String text) {
this.text = text;
}
public Message getNextMessage() {
return nextMessage;
}
public void setNextMessage(Message nextMessage) {
this.nextMessage = nextMessage;
}
}
But when i run this code it gives me the above exception . If i don't use orm.XML the code works fine .. Please help... ,
Will be very much obliged for the same .