OK! Figured this out, and maybe someone can still help me out here...
In the MappedSuperclass class (DateRecord) I changed the annotations from
the field level to the method level (getters). Now I don't need attribute
overrides...
So this begs the question: What is the real different between field and
method level JPA annotations?
parsons68 wrote:
>
> Looking for a simpler approach to handling my inheritance situation...
>
> Tables:
>
> LOCATION
> id (PK)
> ... (PK possibly in here also)
> effective_date
> end_date
> valid
>
> PERSON
> id (PK)
> ...
> effective_date
> end_date
> valid
>
> These two tables are not related. Quite a few of our tables utilize
> effective, end dates, and a valid indicator. The reasoning is
> complicated, but required. However, those columns are not part of the
> key.
>
> With this, it makes sense to have a DateRecord class that contains those
> common attributes.
>
> What I end up with in JPA terms makes things a bit ... difficult.
>
> I've tried setting DateRecord as a MappedSuperclass, however, those
> columns are not able to be queried by (in the where), unless the attribute
> values match the column names. The other way to get it to work is to
> have @AttributeOverrides( {...} ) in the child class to actually give the
> attribute mapping to the column names. This seems to be a bit lame
> considering I've added @Column in the DateRecord class.
>
> Here is some general code:
>
> @MappedSuperclass
> public abstract class DateRecord implements Serializable
> {
> @Temporal(TemporalType.DATE)
> @Column(name = "effective_date")
> private Date effectiveDate;
>
> @Temporal(TemporalType.DATE)
> @Column(name = "end_date")
> private Date endDate;
>
> @Column(name = "valid")
> private String validityIndicator;
>
> ....getter/setters...
> }
>
> @Entity
> @Table(name="Location")
>
> //-- this seems kind of stupid - since..didn't I already define this in
> DateRecord???
> @AttributeOverrides( {AttributeOverride(name="effectiveDate, column =
> @Column(name="effective_date")) ....
> })
>
> public class Location extends DateRecord implements Serializable
> {
> @Id
> @Column(name="id"...)
> private int locationId
>
> .....
> }
>
>
> DAO:
>
> String query = "select model from Location where model.effectiveDate
> >= :effectiveDate";
>
>
>
>
> IF DateRecord is an @MappedSuperclass, this fails unless I have the
> AttributeOverrides. If I set DateRecord as an @Entity, and @Id is
> required somewhere...
>
> My mind is a swirl here, and there has got to be a better way!?
>
>
>
--
View this message in context:
http://www.nabble.com/JPA-Inheritance-tp19314353s2369p19317106.html
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]