JPA / Hibernate OneToMany& ManyToOne注释

时间:2011-10-06 16:27:13

标签: jpa

我正在编写看起来像Google Latitude的代码(找到用户)。 我在tomcat 6.0.33下,使用jpa / hibernate和easybeans 1.1

他们独立工作,但当我尝试链接他们时,它失败了:

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: entity] Unable to build EntityManagerFactory
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

以下是代码:

public class Personne{
 @ManyToOne(fetch=FetchType.EAGER, cascade={ CascadeType.PERSIST,CascadeType.MERGE })
 public Personne getOwner() {
   return owner;
  }
}

public class MaPosition{
 @OneToMany
 public List<Personne> getFriends() {
   return friends;
  }
}

感谢您的帮助;)

2 个答案:

答案 0 :(得分:0)

如果将mappedBy添加到OneToMany,它是否有效?

public class MaPosition{
    @OneToMany(mappedBy="owner")
    public List<Personne> getFriends() {
        return friends;
    }
}

答案 1 :(得分:0)

JPA / Hibernate OneToMany&amp; ManyToOne为班级人员和人员地址注释。 所以一个人可以有很多地址.....我用过它就有用......

一对多......

public class Person{
@OneToMany(mappedBy="person", targetEntity=Address.class, cascade=CascadeType.MERGE)
private Set<Address> addressList = HashSet<Address>();
//Getters and Setters.....
}

多对一......

public class Address{
@ManyToOne
@JoinColumn(name="PERSON_ID")
private Person person;
//Getters and Setters.....
}