Actually I have 2 persistence units in persistence.xml where Gender entity is configured in phase1-pu persistence unit and Person is configured in phase2-pu. In Person entity I want to add @ManyToOne to Gender Entity.
When I start the application getting following error:
[ERROR] Failed to execute goal de.juplo:hibernate-maven-plugin:2.0.0:create (h2-create-pris-p2) on project lookup-rest: Execution h2-create-pris-p2 of goal de.juplo:hibernate-maven-plugin:2.0.0:create failed: @OneToOne or @ManyToOne on my.mimos.entity.Person.gender references an unknown entity: my.mimos.entity.Gender-> [Help 1][ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Following is my setup
persistence.xml
<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/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="phase1-pu">
<class>my.lookup.entity.Gender</class>
</persistence-unit>
<persistence-unit name="pahse2-pu">
<class>my.lookup.entity.Person</class>
</persistence-unit>
Gender.java
@Entity
@Table(name = "REF_GENDER")
public class Gender extends AbstractEntity<Byte> {
@Id
@Access(AccessType.PROPERTY)
private Byte id;
@NotBlank
@Size(max = 100)
@Column(nullable = false, length = 100)
private String name;
@NotBlank
@Size(max = 10)
@Column(nullable = false, length = 10)
private String code;
}
Person.java
@Entity
@Table(name = "REF_PERSON")
public class Person extends AbstractEntity<Byte> {
@Id
@Access(AccessType.PROPERTY)
private Byte id;
@NotBlank
@Size(max = 100)
@Column(nullable = false, length = 100)
private String name;
@NotBlank
@Size(max = 10)
@Column(nullable = false, length = 10)
private String code;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "gender_id")
private Gender gender;
}