我需要你的帮助,使用@ElementCollection注释在两个表的Hibernate中映射关系.
第一个是父
表表名:父
数据库列
KEY1 Char (first primary key field)
KEY2 Char (second primary key field)
DESCRIPTION Char
DEPENDENTID BigInt
Run Code Online (Sandbox Code Playgroud)
第二个是依赖表
TableName:Dependent
DB Columns
PARENTID BigInt (first primary key field)
CODE Char (second primary key field)
FIELD1 Char
FIELD2 Char
Run Code Online (Sandbox Code Playgroud)
我需要使用@EmbeddedId注释为两个表定义PK,所以我创建了两个类:
@Embeddable
public class ParentPK implements Serializable
{
@Column(name="K1")
private String iK1;
@Column(name="K2")
private String iK2;
// I omit the constructor, getter, setter, equals, hashcode method
}
@Embeddable
public class DependentPK implements Serializable
{
@Column(name="PARENTID")
private String iParentId; …Run Code Online (Sandbox Code Playgroud)