Advanced details

Changing column names

By default, the column names are taken from the component. For the recipe examples a column firstImpression will be added to the recipe table. If you want to change column names of a component in an entity, you can use @AttributeOverrides in the annotation mapping, have a look at the Sheep and Pullover example in the same package as the previous example.

Sheep class. 

public class Sheep  {

    // we would like the color field of pullover to be mapped to a different
    // column
    @AttributeOverride(name = "color", column = @Column(name = "pullover_column"))
    private Pullover pullover;

Querying components

You cannot load a component by id or write a query like select a from Address a, but it is still possible to query a list of all addresses. You just have to make use of the owning entity.

List<Address> addresses = session.createQuery
      ("select p.address from Person p")