我有带有 Hibernate 映射类的 Java EE 应用程序(我使用 *.hbm.xml 映射)。现在我需要使用 JPA 注释重新制作映射。一切都很好,但我无法使用我的 Map 属性创建正确的映射。
@Entity
@Table(name = DataBaseConstants.EMPLOYEE_TABLE)
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = DataBaseConstants.EMPLOYEE_ID, sequenceName = DataBaseConstants.EMPLOYEE_SEQ)
@GeneratedValue(generator = DataBaseConstants.EMPLOYEE_ID)
@Column(name = DataBaseConstants.EMPLOYEE_ID)
private long id = 0;
@Column(name = DataBaseConstants.EMPLOYEE_NAME)
private String name = null;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = DataBaseConstants.ADDRESS_ID_FK)
private Address address = null;
private Map<Office, Position> officePositions = null;
这是数据库中数据模型的一部分。 DB MODEL IMAGE (对不起,我无法发布图片)请帮我映射 officeEmployee MAP
在休眠中,我使用了这种方式,一切正常。
<map name="officePositions" table="EMPLOYEE_POSITION_OFFICE" lazy="false"
fetch="join" batch-size="100">
<key>
<column name="EMPLOYEE_ID"></column>
</key>
<map-key-many-to-many class="com.example.jpajdbctask.entities.Office">
<column name="OFFICE_ID">
</column>
</map-key-many-to-many>
<many-to-many column="POSITION_ID"
class="com.example.jpajdbctask.entities.Position" />
</map>