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
To my knowledge, yes, you need to.
The tutorial How to use Compound Primary Keys with Hibernate and JPA Annotations does a great job at summarizing the various options (
@Idvs@IdClassvs@EmbeddedId) and, in my opinon, the latter is the easiest way (less verbose).