[hibernate - jpa] @OneToOne annotoation problem (i think...)
- by blow
Hi all, im new in hibernate and JPA and i have some problems with annotations.
My target is to create this table in db (PERSON_TABLE with personal-details)
ID ADDRESS NAME SURNAME MUNICIPALITY_ID
First of all, i have a MUNICIPALITY table in db containing all municipality of my country.
I mapped this table in this ENTITY:
@Entity
public class Municipality implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String country;
private String province;
private String name;
@Column(name="cod_catasto")
private String codCatastale;
private String cap;
public Municipality() {
}
...
Then i make an EMBEDDABLE class Address containing fields that realize a simple address...
@Embeddable
public class Address implements Serializable {
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="id_municipality")
private Municipality municipality;
@Column(length=45)
private String address;
public Address() {
}
...
Finally i embedded this class into Person ENTITY
@Entity
public class Person implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String name;
private String surname;
@Embedded
private Address address;
public Person() {
}
...
All works good when i have to save a new Person record, in fact hibernate creates a PERSON_TABLE as i want, but if i try to retrieve a Person record i have an exception.
HQL is simply "from Person"
The excpetion is (Entities is the package containing all classes above-mentioned):
org.hibernate.AnnotationException: @OneToOne or @ManyToOne on Entities.Person.address.municipality references an unknown entity: Entities.Municipality
Is the @OneToOne annotation the problem?
Thanks.