Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA error: Generated Insert statement has more columns than existing in DB [Column not unique]

 
Anil Kumar Tota
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I have the following database tables:

create table "SAPN73DB"."OEE_KPI"(
"CLIENT" VARCHAR (3) UNICODE not null,
"KPI" VARCHAR (20) UNICODE not null,
"KPI_TYPE" VARCHAR (50) UNICODE,
"UOM_OF_TARGETS" VARCHAR (50) UNICODE,
constraint SYSPRIMARYKEY primary key ("CLIENT","KPI"))

create table "SAPN73DB"."OEE_KPIT"(
"CLIENT" VARCHAR (3) UNICODE not null,
"KPI" VARCHAR (20) UNICODE not null,
"LANG" VARCHAR (2) UNICODE not null,
"DESCRIPTION" VARCHAR (50) UNICODE,
constraint SYSPRIMARYKEY primary key ("CLIENT","KPI","LANG"))



The "OEE_KPI" is the parent table and "OEE_KPIT" is the child table, so there is a one to many relationship. The Join columns are "CLIENT" and "KPI".

Hence I created the corresponding JPA classes:

================================================================

================================================================


================================================================



================================================================

================================================================

Now when I execute the following code:


I am getting an error saying:

Caused by: com.sap.sql.log.OpenSQLException: The SQL statement "INSERT INTO "OEE_KPIT" ("CLIENT","KPI","LANG","DESCRIPTION","CLIENT","KPI") VALUES (?,?,?,?,?,?)" contains the semantics error[s]: - 1:61 - column ""CLIENT"" not unique
- 1:70 - column ""KPI"" not unique

Can anyone help me why the "CLIENT" and "KPI" field is added again in the insert statement? Kindly help me in fixing this error.

Regards,
Anil.
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use Code Tags. I would help but I am unwilling to go through so much unformatted text.
 
Anil Kumar Tota
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Manuel,
Thanks a lot for your reply. I have added the code tags. Thanks in advance for you help.

Regards,
Anil.
 
James Sutherland
Ranch Hand
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue is you are mapping the columns twice in the EmbeddedId and the ManyToOne. You could remove the EmbeddedId and just add @Id to the ManyToOne and add an IdClass.

Or, you could make one set of the columns insertable=false, updateable=false.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Primary_Keys_through_OneToOne_and_ManyToOne_Relationships
 
Anil Kumar Tota
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot James. The issue is solved by adding insertable=false, updateable=false
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic