我有两个实体: 目的地(密钥id1,密钥id2dept和非密钥名称1) 和服务(密钥id3和非密钥名称2)。
当我使用目标 - > Service
Destination
中使用OneToMany生成架构时
@OneToMany(cascade=ALL, fetch=FetchType.EAGER)
private Collection<Destination> d;
我收到一个只有两个键的Join表:Joinedtable(键id3,键id1) 我期待Joinedtable(密钥id3,密钥id1,密钥id2)
使用JOIN的SQL知识,我理解如果基于id1 = id3加入,那么我应该收到 Joinedtable(id1,id2dept)。 但即使不接受,我哪里出错?
@Entity
@Table(name = "BHU_DST")
public class TMP_Destb implements Serializable {
private long id1;
private long id2dept;
private char name;
private static final long serialVersionUID = 1L;
//getter and setter
}
@Entity
@Table(name = "BHU_SVC")
public class TMP_Servb implements Serializable {
private long id2;
private char name2;
private static final long serialVersionUID = 1L;
@OneToMany(cascade=ALL, fetch=FetchType.EAGER)
private Collection<TMP_Destb> d;
//getter and setters
}
public class TMP_DestinationPK implements Serializable {
private long id1;
private long id2dept;
private static final long serialVersionUID = 1L;
//getters setters and hashcodes
}
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="1.0" xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
<entity class="mypkg.jpa1.TMP_Destb" access="FIELD">
<id-class class="TMP_DestinationPK"/>
<attributes>
<id name="id1">
</id>
<id name="id2dept">
</id>
</attributes>
</entity>
<entity class="mypkg.jpa1.TMP_Servb" access="FIELD">
<attributes>
<id name="id2">
</id>
</attributes>
</entity>