我们正在尝试使用基本的@OneToMany 关系:
@Entity
@Table(name = "PARENT_MESSAGE")
public class ParentMessage {
@Id
@Column(name = "PARENT_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer parentId;
@OneToMany(mappedBy="parentMsg",fetch=FetchType.LAZY)
private List childMessages;
public List getChildMessages() {
return this.childMessages;
}
...
}
@Entity
@Table(name = "CHILD_MSG_USER_MAP")
public class ChildMessage {
@Id
@Column(name = "CHILD_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer childId;
@ManyToOne(optional=false,targetEntity=ParentMessage.class,cascade={CascadeType.REFRESH}, fetch=FetchType.LAZY)
@JoinColumn(name="PARENT_ID")
private ParentMessage parentMsg;
public ParentMessage getParentMsg() {
return parentMsg;
}
...
}
ChildMessage child = new ChildMessage();
em.getTransaction().begin();
ParentMessage parentMessage = (ParentMessage) em.find(ParentMessage.class, parentId);
child.setParentMsg(parentMessage);
List list = parentMessage.getChildMessages();
if(list == null) list = new ArrayList<ChildMessage>();
list.add(child);
em.getTransaction().commit();
我们收到以下错误。为什么 OpenJPA 将表名连接到APP.PARENT_MESSAGE_CHILD_MSG_USER_MAP
? 当然该表不存在..定义的表是APP.PARENT_MESSAGE
和APP.CHILD_MSG_USER_MAP
原因:org.apache.openjpa.lib.jdbc.ReportingSQLException:表/视图“APP.PARENT_MESSAGE_CHILD_MSG_USER_MAP”不存在。{SELECT t1.CHILD_ID, t1.PARENT_ID, t1.CREATED_TIME, t1.USER_ID FROM APP.PARENT_MESSAGE_CHILD_MSG_USER_MAP t0 INNER JOIN APP.CHILD_MSG_USER_MAP t1 ON t0.CHILDMESSAGES_CHILD_ID = t1.CHILD_ID WHERE t0.PARENTMESSAGE_PARENT_ID,= state = ? 42X05]