I have classes Clinic, Test and joinclass TestClinic.
Code:
@Entity
@Table(name = "Test")
public class Test {
private long id;
private String name;
@Id
@GeneratedValue
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
Code:
@Entity
@Table(name = "Clinic")
public class Clinic {
private long id;
private String name;
public Clinic() {
}
@Id
@GeneratedValue
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
And the join class with extra column (price):
Code:
@Entity
@Table(name = "TestClinic")
public class TestClinic {
private float price;
private Test test;
private Clinic clinic;
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
//@Id
@ManyToOne
@JoinColumn(name="test_id")
public Test getTest() {
return test;
}
public void setTest(Test test) {
this.test = test;
}
//@Id
@ManyToOne
@JoinColumn(name="clinic_id")
public Clinic getClinic() {
return clinic;
}
public void setClinic(Clinic clinic) {
this.clinic = clinic;
}
}
Code:
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: pl.diagno.model.vo.TestClinic
I know that the problem is with lack of @Id... I tried to add @Id before getters of Clinic and Test, but there is another exception:
Code:
Caused by: org.hibernate.MappingException: Could not determine type for: pl.diagno.model.vo.Test, for columns: [org.hibernate.mapping.Column(test)]
Where should I add @Id or maybe should I design classes in the another way? But how? :|
Help appreciated!