1

Similar to Hibernate : How override an attribute from mapped super class and Inheritance and @AttributeOverride on @Id field but with a simpler case. I just want to change the name of the class

ER

CREATE TABLE `billing_target` (
  `billingTargetID` int(11) NOT NULL,
  `targetType` char(5) NOT NULL,
  `targetID` int(11) NOT NULL
  PRIMARY KEY (`billingTargetID`)
);

CREATE TABLE `Client` (
  `clientID` int(11) NOT NULL,
  `name` varchar(200),
  PRIMARY KEY (`clientID`)
);

Here's my attempt so far

@Data
@Entity
public class BillingTarget implements Serializable {
    @Id
    @Column(name = "BillingTargetID")
    private Integer id;
}

@Data
@Entity
@Table(name = "Client")
@DiscriminatorValue("CLIENT")
@EqualsAndHashCode(callSuper = true)
@AttributeOverride(
    name = "id",
    column = @Column(name = "ClientID")
)
public class Client extends BillingTarget {
    private String name;
}

However, my queries are looking for Client.BillingTargetID rather than Client.ClientID

Since I @AttributeOverride it is ignored.

@AttributeOverride or @AttributeOverrides in conjunction with entity inheritance is not supported:

If I make BillingTarget a @MappedSuperclass I would get

Caused by: java.lang.NullPointerException at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1745)

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
  • This is a classic example of why I insist on the primary key column being named `id` in all cases. There's every reason to, and just no good reason not to. If it needs to be *rendered* as "clientId", that's a concern for the UI layer and should affect correct database design and adhering to standards. – Bohemian Aug 31 '20 at 22:35
  • Legacy DB. Just trying to map the JPA onto it. It's actually worse than what I wrote there. See https://stackoverflow.com/questions/63637339/how-to-map-a-onetoone-with-zerooronetoone-back-reference-in-jpa the actual thing was a targetID but I found out I that BillingTargetID and TargetID are always equal. – Archimedes Trajano Aug 31 '20 at 23:34

0 Answers0