我看到存在多种方法来映射具有JPA的复合键 。
但在我的情况下有点不同:
我有一个只有2列的表:
mysql> desc mytable; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | name | varchar(80) | NO | PRI | | | | tag | varchar(80) | NO | PRI | | | +--------+-------------+------+-----+---------+-------+我的观点是:我是否需要创建一个新的( 主键类 )类来映射我的复合键?
我正在努力寻找最简单的方法。
有人可以帮我吗?
提前致谢!
我正在尝试这种方法: http : //www.java.net/print/236710
I saw that exist more then one way to map a Composite Key with JPA.
But in my case is kind of different:
I have a table with only 2 column:
mysql> desc mytable; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | name | varchar(80) | NO | PRI | | | | tag | varchar(80) | NO | PRI | | | +--------+-------------+------+-----+---------+-------+My point is: Do I need to create a new (primary key class) class just to map my composite key?
I'm trying to find the easiest way to do it.
Some one can help-me?
Thanks in advance!
I'm trying with this approach: http://www.java.net/print/236710
最满意答案
我是否需要创建一个新的(主键类)类来映射我的复合键?
据我所知,是的,你需要。
我正在努力寻找最简单的方法。
教程如何使用带有Hibernate和JPA Annotations的复合主键在总结各种选项( @Id vs @IdClass vs @EmbeddedId )方面@IdClass ,而且在我看来,后者是最简单的方法(不那么详细)。
Do I need to create a new (primary key class) class just to map my composite key?
To my knowledge, yes, you need to.
I'm trying to find the easiest way to do it.
The tutorial How to use Compound Primary Keys with Hibernate and JPA Annotations does a great job at summarizing the various options (@Id vs @IdClass vs @EmbeddedId) and, in my opinon, the latter is the easiest way (less verbose).
更多推荐
发布评论