开发者

JPA One to Many using JoinTable Error

开发者 https://www.devze.com 2023-01-31 22:11 出处:网络
I am trying to model 1:N (Person & Address) relationship using a junction table (Person_Address).

I am trying to model 1:N (Person & Address) relationship using a junction table (Person_Address).

1.Person (personId PK)

2.Address (addressId PK)

3.PersonAddress ( personId, addressId composite PK, personId FK r开发者_如何学Goeferences Person, addressid FK references Address )

@Entity 
public class Person {  

@OneToMany   
@JoinTable(
    name="PersonAddress", 
    joinColumns = @JoinColumn( name="personId"),     
    inverseJoinColumns = @JoinColumn( name="addressId")    
)   

public Set<Address> getAddresses() {...}  ... 
} 

I encounter following error. Not able to find any solution.

Caused by: org.hibernate.MappingException: Could not determine type for: com.realestate.details.Address, at table: Person, for columns:

[org.hibernate.mapping.Column(address)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:269) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253) at org.hibernate.mapping.Property.isValid(Property.java:185) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440) at org.hibernate.mapping.RootClass.validate(RootClass.java:192) at org.hibernate.cfg.Configuration.validate(Configuration.java:1108) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1293)


  1. Make sure you don't have @Column private Address address in your Person entity
  2. Make sure Address is mapped as @javax.persistence.Entity
0

精彩评论

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