Home > Back-end >  GeneratedValue and GenericGenerator primary key on the question
GeneratedValue and GenericGenerator primary key on the question

Time:09-30

Recently met a problem:
I am after using jpa, the database Settings for int primary key on the type,
Use the following way

 @ Id@ GeneratedValue (generator="generator") 
@ GenericGenerator (name="generator", the strategy="identity")
@ the Column (name="accountid")

Save data when an error: Java. SQL. SQLSyntaxErrorException: Table 'testdb. The generator' doesn 't exist
It is obvious that he will be my name. Table name pointing to the generator

The class code:
 @ Entity 
@ Table (name="test_account", the catalog="testdb")
@ DynamicUpdate
Public class Account implements Java. IO. Serializable {
Private Integer accountid;
private String name;

@ Id
@ GeneratedValue (generator="generator")
@ GenericGenerator (name="generator", the strategy="identity")
@ the Column (name="accountid")
Public Integer getAccountid () {
Return the accountid;
}
Public void setAccountid (Integer accountid) {
Enclosing accountid=accountid;
}
@ the Column (name="name")
Public String getName () {
return name;
}
Public void elegantly-named setName (String name) {
this.name=name;
}

}


But if I change the database main keys to varchar (36), set the uuid

 @ Id@ GeneratedValue (generator="generator") 
@ GenericGenerator (name="generator", the strategy="uuid. Hex")
@ the Column (name="accountid")

It is no problem,

The problem, no problem at compile time, only when the save, complains

PS: if only int, pure jpa annotations Settings, also can save a success, but a mixture of hibernate annotations, it failed!

 @ Id@ GeneratedValue (strategy=GenerationType. IDENTITY) 
@ the Column (name="accountid")

CodePudding user response:

Here, I just wondered why the jpa and hibernate complains are used,

But in my another project, the two labels in the case of a primary key on the can be used together,
But I couldn't find two projects, set on the difference between
Very confusing, have to know?

CodePudding user response:

I still go to the spring community ask,
  • Related