开发者

JPA/Hibernate OneToMany & ManyToOne annotations

I'm writing code that looks like Google Latitude (locate a user). I'm under tomcat 6.0.33, using jpa/hibernate, and easybeans 1.1

They work independently, but when I try to link them it fails:

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]

Here is the code:

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;
  }
开发者_开发百科}

Thanks for your help ;)


does it work if you add a mappedBy to your OneToMany?

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


JPA/Hibernate OneToMany & ManyToOne annotations for class person and person address. So one person can have many addresses..... and I used this It worked...

One to many....

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

Many to one....

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜