我有两个具有双向关系的类:
@Entity
@Access(AccessType.FIELD)
@Table(name="ROOM")
public class Room {
@Id
@GeneratedValue
@Column(name="ROOM_ID_PK", updatable=false, nullable=false)
private int id;
@Column(name="NAME", nullable=false, unique=true)
private String name;
@OneToMany(mappedBy="room", cascade={CascadeType.ALL})
private final Set<Wall> walls;
...
}
@Entity
@Access(AccessType.FIELD)
@Table(name="WALLS")
public class Wall {
@Id
@GeneratedValue
@Column(name="WALL_ID_PK", updatable=false, nullable=false)
private int id;
@Column(name="NAME", nullable=false, unique=true)
private String name;
@ManyToOne
@JoinColumn(name="ROOM_ID_FK", referencedColumnName="ROOM_ID_PK")
private Room room;
...
}
我正在运行 mysql——生成了一组看起来很正常的表:
ROOMS: INT ROOM_ID_PK, VARCHAR NAME
WALLS: INT WALL_ID_PK, VARCHAR NAME, INT ROOM_ID_FK
但是,当我执行 JPQL 查询时
SELECT w FROM Wall w, Room r WHERE w MEMBER OF r.walls AND r = :room
我收到一个错误:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'wall' threw exception; nested exception is <openjpa-2.0.1-r422266:989424
nonfatal user error> org.apache.openjpa.persistence.ArgumentException:An error occurred
while parsing the query filter "SELECT w FROM Wall w, Room r WHERE w MEMBER OF r.walls
AND r = :room". Error message: No field named "walls" in "Room". Did you mean "name"?
Expected one of the available field names in "mypackage.Room": "[id, name]".
由于某种原因,“墙”没有被视为 Room 类的一个领域。这段代码在休眠状态下工作——我正在尝试迁移到 OpenJPA,但遇到了这个错误。我已经确认这两个类都在我的 persistence.xml 中定义。