Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以使用Hibernate将Java对象映射到具有FK关系的多个表?_Java_Mysql_Spring_Hibernate - Fatal编程技术网

是否可以使用Hibernate将Java对象映射到具有FK关系的多个表?

是否可以使用Hibernate将Java对象映射到具有FK关系的多个表?,java,mysql,spring,hibernate,Java,Mysql,Spring,Hibernate,我有3个表以及上面描述的表之间的关系 我是新来Hibernate的,我想知道是否可以将上面的表映射到一个实体中?我知道@SecondaryTable注释,但我不确定是否可以在这里使用它,因为表1和表3之间没有直接关系 如果可能,hibernate是否足够聪明,可以先将行插入到表1中,然后使用返回的id将列插入到表2中 我已经进行了大量搜索,但尚未找到解决此问题的方法。您可以在Hibernate域对象中查找自动生成的id,而不是自动增加DB @Id @GeneratedValue(strategy

我有3个表以及上面描述的表之间的关系

我是新来Hibernate的,我想知道是否可以将上面的表映射到一个实体中?我知道@SecondaryTable注释,但我不确定是否可以在这里使用它,因为表1和表3之间没有直接关系

如果可能,hibernate是否足够聪明,可以先将行插入到表1中,然后使用返回的id将列插入到表2中


我已经进行了大量搜索,但尚未找到解决此问题的方法。

您可以在Hibernate域对象中查找自动生成的id,而不是自动增加DB

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
protected Long c_id;
那么在你的流程中,你不能这样做吗

@Transactional(propagation = Propagation.REQUIRES_NEW)
method m1()
{
entity1 = entityManager.persist(entity1)
entityManager.flush();
// At this stage since entity Manager is flushed you will have the id's
// So manually set the id's to entity2
entity2.setForeignKey(entity1.getId());
entityManager.flush();
.
.
.
}