JPA Composite键(所有字段都不是Null和PRI)(JPA Composite key (all fields are notNull and PRI))

编程入门 行业动态 更新时间:2024-10-28 08:16:28
JPA Composite键(所有字段都不是Null和PRI)(JPA Composite key (all fields are notNull and PRI))

我看到存在多种方法来映射具有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).

更多推荐

本文发布于:2023-08-01 16:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1361258.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   Null   JPA   Composite   fields

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!