通过反射持久属性访问字段xxx时出错

时间:2016-07-02 16:32:50

标签: hibernate jpa

我不知道发生了什么事。我的jpa映射看起来很好,但是我收到了这个错误:

  

访问字段[private main.java.entities.User时出错   main.java.entities.GPSCoordinates.user]通过反射来表示持久性   property [main.java.entities.GPSCoordinates #user]:   main.java.entities.GPSCoordinates

Caused by: javax.persistence.PersistenceException: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private main.java.entities.User main.java.entities.GPSCoordinates.user] by reflection for persistent property [main.java.entities.GPSCoordinates#user] : main.java.entities.GPSCoordinates@1
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)
    at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:560)
    at main.java.lookup.UserServiceImp.findByUuid

用户类:

@Entity
@Table
@NamedQuery(name = "User.findByUuid", query = "SELECT u FROM User u WHERE u.uuid=:uuid")
public class User implements Serializable, PictureHolder {
    //...
    @OneToOne(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
    private GPSCoordinates coordinates;

    public GPSCoordinates getCoordinates() { return coordinates;}
    public void setCoordinates(GPSCoordinates coordinates) {this.coordinates = coordinates;}
}

GPSCoordinates类:

@Entity
@Table(name="user_gps_coordinates")
public class GPSCoordinates implements Serializable{

    @Id
    @OneToOne
    @JoinColumn(name="user")
    private User user;

    public User getUser() { return user; }
    public void setUser(User user) {this.user = user;}
}

1 个答案:

答案 0 :(得分:0)

更改

@JoinColumn(name="user")

@JoinColumn(name="column_name_of_user_id")