3

Is there any way to override column name when TABLE_PER_CLASS inheritance is used?

The doc says:
"The limitation of this approach is that if a property is mapped on the superclass, the column name must be the same on all subclass tables." :(

@AttributeOverride does not work

Example:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Parent {
  @Id
  String id;

  String parentProperty;
}

@Entity
public class Child extends Parent {
}

and some sample query

entityManager.createQuery("select p.parentProperty from Parent p", String.class).getResultList()

produces

select
    parent0_.parentProperty as col_0_0_ 
from
    ( select
        id,
        parentProperty,
        1 as clazz_ 
    from
        Child ) parent0_

Is there any way to force Hibernate to use some custom property name in child subqueries ? The problem is that I have some legacy DB with few tables that hold pretty the same data but some column names differ...

Edit: I have ended up with the views containing renamed column names

Paweł Kaczorowski
  • 1,502
  • 2
  • 14
  • 25

0 Answers0