Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error accessing field xxx by reflection for persistent property

Tags:

hibernate

jpa

I don't know what's up. My jpa mapping seems fine, yet I get this error :

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

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

User class:

@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 class:

@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;}
}
like image 376
Ced Avatar asked Jul 02 '16 16:07

Ced


1 Answers

Change

@JoinColumn(name="user")

to

@JoinColumn(name="column_name_of_user_id")
like image 89
Hoang Nguyen Avatar answered Oct 20 '22 02:10

Hoang Nguyen