-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mapping with annotations and inheritance
PostPosted: Mon Dec 01, 2008 10:07 am 
Newbie

Joined: Tue Aug 07, 2007 3:19 am
Posts: 5
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.