dimanche 22 février 2015

JPA: Using @MapKey for an abstract class



I have the following structure of an abstract superclass A and a class Z referring to As sublasses B and C using a map:



@Entity
Abstract Class A
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
Integer map_field; <----------------------- Problematic
....

@Entity
Class B extends A
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
Integer map_field;
....

@Entity
Class C extends A
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
Integer map_field;
....

@Entity
Class Z
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@OneToMany(cascade = CascadeType.ALL)
@MapKey(name="map_field")
private Map<Integer,A> a_entities;


The problem is that the map_field is based on values of the objects B and C and not on class values of A.


So basically I cannot use the map_field using the @MapKey annotation in class Z as written above. I do not have useful values for the map_field of class A.


Does anyone have hints how I can solve this problem?


Thanks in advance, Alex




Aucun commentaire:

Enregistrer un commentaire