Home » Java » java hibernate jpa AttributeOverride Id problem-Exceptionshub

java hibernate jpa AttributeOverride Id problem-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

public class A{

 private int id;


@Entity @Table( name = "B_table" )
@AttributeOverride ( name = "id" , column = @Column( name ="B_id" ) )
public class B extends A{


hi I’m trying to override the Id Column name. My tables always have their ID column name prefixed with the table name e.g for table PERSON the id column is PERSON_ID, while in our java model, our classes inherit from a generic superclass that has a field called id with a JPA annotation @Id

Simple persistence tests on this code pass. But hibernate appears to get confused when its asked to generates SQL queries from these classes, often creating queries that include columns with both (name prefixed)id and id, the latter causing errors since we don’t have tables with column name = ‘id’.

I’ve red questions elsewhere that suggest AttributeOverride is not designed to mod the hibernate model, and so can not do what I want it to do here. Anyone got any solutions, suggestions ?

How to&Answers: