假设我有这 3 个表:
CREATE TABLE "entity1" (
"id" int4 NOT NULL,
"name" text NOT NULL,
CONSTRAINT "entity1_pkey" PRIMARY KEY("id")
);
CREATE TABLE "entity2" (
"id" int4 NOT NULL,
"entity1_id" int4 NOT NULL,
"param_name" text NOT NULL,
"entity3_id" int 4 NOT NULL,
CONSTRAINT "entity2_pkey" PRIMARY KEY("id")
CONSTRAINT "fk_entity2_to_1" FOREIGN KEY "entity1_id" REFERENCE entity1("id")
CONSTRAINT "fk_entity2_to_3" FOREIGN KEY "entity3_id" REFERENCE entity3("id")
);
CREATE TABLE "entity3" (
"id" int4 NOT NULL,
"name" text NOT NULL,
CONSTRAINT "entity3_pkey" PRIMARY KEY("id")
);
我需要将entity2表映射到entity1类中,其中映射值的类型是Entity3。换句话说,我在“Entity1”Hibernate java bean 中需要类似的东西:
public class Holder {
private Long id;
private String name;
private Map<String, Entity3> data;
}
这是我现在所在的位置:
<hibernate-mapping package="test">
<class name="Entity1" table="entity1">
<id name="id" type="long" column="id">
<generator class="native">
</id>
<property name="activated" column="activated" type="boolean" />
<map name="data" table="entity2" cascade="all">
<key column="entity1_id" />
<map-key column="param_name" type="java.lang.String" />
< ??????????????????????????? >
</map>
</class>
</hibernate-mapping>
< ???????????? > 是我无法找到的部分。
最佳答案
<???????> -> <many-to-many column="entity3-id" class="entity3" />
希望这对您有帮助。
关于java - Hibernate映射<基本,实体>映射(3个表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28371069/