Posts Tagged ‘hibernate’

Extending EJB3 Objects

December 2, 2009 Leave a comment

Small and fast tip.

In order to be able to extend an EJB Entity object (be it a main object or a primary key embbedable) you need to write the MappedSuperclass anotation in the super class.

The following is taken from hibernate documentation :

public class BaseEntity {
    public Date getLastUpdate() { ... }
    public String getLastUpdater() { ... }

@Entity class Order extends BaseEntity {
    @Id public Integer getId() { ... }

Some other notes taken from the documentation :

  • Properties from superclasses not mapped as @MappedSuperclass are ignored;
  • The access type (field or methods), is inherited from the root entity, unless you use the Hibernate annotation @AccessType;
  • Any class in the hierarchy non annotated with @MappedSuperclass nor @Entity will be ignored.

Read the documentation to understand it fully : chapter

Please note that even though i’ve used the Hibernate documentation as a reference this anotation also exists in javax.persistence so it can be used with JPA

Categories: ejb3, java Tags: , ,