• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Annotations mapping with inheritance

 
Sverre Moe
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been able to convert 80% of my hibernate mapping file to Java Annotations mapping.
For some of my domain objects I have hit a wall.

The primary domain object is an abstract class. It contains some commons attributes for CustomerAgreement and ServiceAgreement.
The two latter domain objects are two seperate tables, but they share many similar attributes (though not the same name of the attributes, CA_NAME, SA_NAME).

How can I configure annotations mapping in the primary object when those attributes have different column names for the two child objects.
The primary domain object is not realy an entity. Another problem is that these child objects share one part of the primary key in the abstract parent class.

@MappedSuperclass
public abstract class Agreement{
private Integer primaryKeyA;
}

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "CA_OPT", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("CA")
@Table(name = "CustomerAgreement")
public class CustomerAgreement extends Agreement {
@Column(name = "CA_PK2) private Integer primaryKeyCA;
}

@Entity
@Table(name = "ServiceAgreement")
public class ServiceAgreement extends Agreement {
@ManyToOne Column(name = "SA_PK2) private MyObject primaryKeySA1
@Column(name = "SA_PK3) private Integer primaryKeySA2;
@Column(name = "SA_PK4) private Integer primaryKeySA3;
}

@MappedSuperclass
public abstract class DetailedAgreement extends CustomerAgreement {
@Column(name = "CA_AGRDET") private AgreementDetails agreementDetails;
}

@DiscriminatorValue("ONE")
public class Agreement1 extends DetailedAgreement { ... }

For some of the CustomerAgreements I have spesialized domain objects that is based upon the abstract class DetailedAgreement.
These spesialized classes uses a discriminator-value, but they have no database tables.
Where do I define the @Inheritance annotations. With DetailedAgreement or CustomerAgreement?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic