开发者

JPA/Hibernate OneToMany & ManyToOne annotations

开发者 https://www.devze.com 2023-04-11 11:27 出处:网络
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

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

精彩评论

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