无法在JPA中将身份列密钥生成与策略TABLE_PER_CLASS一起使用? [英] Cannot use identity column key generation with the strategy TABLE_PER_CLASS in JPA?

查看:72
本文介绍了无法在JPA中将身份列密钥生成与策略TABLE_PER_CLASS一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与

This question is in context with the problem mentioned in this thread. I'm also facing the same problem while using JPA on MySQL. I could resolve it only when I changed the generation strategy to TABLE.

但是问题是,此问题背后的原因是什么,为什么将策略更改为TABLE是解决方案(在

But the question is, what was the reason behind this problem and why changing the strategy to TABLE is the solution (this remains unanswered in the thread) ?

推荐答案

要通过继承层次结构拥有唯一的ID(JPA要求),您显然不能使用TABLE_PER_CLASS和IDENTITY来做到这一点,因为IDENTITY是在一个表上工作的,并且存在现在继承层次结构中有多个根"表.

To have unique ids through an inheritance hierarchy (which JPA requires), you obviously cannot do that with TABLE_PER_CLASS and IDENTITY since IDENTITY works off a table, and there are now multiple "root" tables in the inheritance hierarchy.

例如抽象基类"Base"以及子类"Sub1","Sub2","Sub3". 因此,您有实际的表"SUB1","SUB2","SUB3".因此,如果使用IDENTITY,则相当于使用MySQL时,列上的"autoincrement"之类的东西.因此,SUB1具有其ID,SUB2具有其ID,而SUB3具有其ID ...,它们是独立的,因此可以在ID中发生冲突...,因此在继承层次结构中不再具有唯一ID.

e.g abstract base class "Base", and subclasses "Sub1", "Sub2", "Sub3". So you have actual tables "SUB1", "SUB2", "SUB3". So if using IDENTITY then this will equate to something like "autoincrement" on a column when using MySQL. Hence SUB1 has its ids, SUB2 has its ids, and SUB3 has its ids ... and they are independent, hence can get collisions in id ... so you no longer have unique id in the inheritance hierarchy.

这篇关于无法在JPA中将身份列密钥生成与策略TABLE_PER_CLASS一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆