1

I want to set the primary key constraint name as MyEmbeddable_PK, which is dynamically generated as PK__MyEmb__ED24807C4DAE15BD from hibernate. How to override that created primary key constraint so that MyEmbeddable_PK could be generated from hibernate instead of the dynamically created one ?

My entity is as below

@Entity
public class MyBaseEntity {

   @EmbeddedId
   private MyEmbeddable id;

   // other...
}
lt.price
  • 79
  • 1
  • 7
  • I would expect it to work similarly to any other `@Id`: https://stackoverflow.com/q/32160370/2342957 – Thelonius Mar 04 '20 at 13:43
  • I think you have identified the question incorrectly. What i want is to define a `composite primary key`, where as in the solution you mentioned it only has a `primary key` also the suggested solution is not working for my case. Anyways Thank you. – lt.price Mar 04 '20 at 15:00
  • But you can also add multiple columns in the index definition, so an index for a composite id should also be doable. But maybe I really did not fully understand your intent. – Thelonius Mar 05 '20 at 15:27
  • @thelonius This is regarding the question duplication you said. If it is similar it would have been something like this. ```sql CREATE TABLE ACCOUNT( ID INT NOT NULL IDENTITY (1,1), USERNAME VARCHAR(50) NOT NULL, PASSWORD VARCHAR(50) NOT NULL, EMAIL VARCHAR(100) NOT NULL, CONSTRAINT PK_tblAccount_ID PRIMARY KEY (ID, USERNAME) ) ``` – lt.price Sep 25 '20 at 09:37
  • but my problem is something like this, ```sql CREATE TABLE ACCOUNT( USERNAME VARCHAR(50) NOT NULL, EMAIL VARCHAR(100) NOT NULL, PASSWORD VARCHAR(50) NOT NULL, CONSTRAINT PK_tblAccount_ID PRIMARY KEY (USERNAME, EMAIL) ) ``` So [link](https://stackoverflow.com/questions/32160370/hibernate-constraint-name) is not similar to mine. – lt.price Sep 25 '20 at 09:38
  • 1
    Well, according to this answer https://stackoverflow.com/q/25832552/2342957 it's not possible to rename the primary key index, as it is created by Oracle, before Hibernate will create its indexes. Which underlying database are you using? – Thelonius Sep 28 '20 at 12:46

0 Answers0