0

Is it absolutely mandatory for the primary key of a Hibernate model (entity) to be a field rather than a property? I have a table, say 'Purchase', whose primary key, say, cust_id, also acts as a foreign key to a 'Cust' table. Can I define the primary key as a 'Cust' type instead of an int type? What annotations do I need to use? Can someone share a sample code if the above is possible?

so1
  • 58
  • 1
  • 10

1 Answers1

0

Have a look at the discussion here @ SO.

In discussion it states you can use @Id and @ManyToOne on a forign key mapping.

Is it absolutely mandatory for the primary key of a Hibernate model (entity) to be a field rather than a property?

No its not mandatory, for composite primary keys scenario you can have POJOs as primary key have a look at section on composite primary keys in hibernate docs

Community
  • 1
  • 1
baba.kabira
  • 3,111
  • 2
  • 26
  • 37