gpt4 book ai didi

java - JPA Composite key(所有字段都不是Null和PRI)

转载 作者:行者123 更新时间:2023-11-29 08:18:55 24 4
gpt4 key购买 nike

我看到存在不止一种方法可以将 Composite Key 映射到 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


最佳答案

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.

教程How to use Compound Primary Keys with Hibernate and JPA Annotations在总结各种选项方面做得很好(@Id vs @IdClass vs @EmbeddedId),在我看来,后者是最简单的方法(不那么冗长)。

关于java - JPA Composite key(所有字段都不是Null和PRI),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1923580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com