У меня есть следующее @MappedSuperClass и @Entity:Почему мой @MappedSuperClass не работает?
@MappedSuperclass
public class SuperClass implements Serializable {....}
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name = "TABLE1")
public class Table1 extends SuperClass implements Serializable {...}
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name = "TABLE2")
public class Table2 extends SuperClass implements Serializable {...}
В базе данных, как таблицы имеют одинаковые столбцы, так что все мои атрибуты находятся в SuperClass:
@Id
private String attr1;
@Id
private String attr2;
@Column(name="DATA")
private String data;
// getters and setters
Но когда я пытаюсь выполнить запрос с одним из @Entity (table1 или table2), я получаю OpenJPA ОШИБКА:
Error pre-processing class table1 with we[email protected]205c54b'
<openjpa-1.1.0-r422266:657916 fatal user error>
org.apache.openjpa.util.MetaDataException: Type "class SuperClass" with application identity and no superclass does not declare an id class.
This type is not eligible for builtin identity, so it must declare an id class.
Я не понимаю, почему атрибут @Id не Fo и в классе @Entity.
Если кто-нибудь есть какие-либо идеи, не стесняйтесь, чтобы помочь мне :)
С уважением,
Cytemax
Мой класс @Entity должен иметь @IdClass (SuperClassPK.class), потому что мой первичный ключ содержит два свойства (attr1 & attr2). – Cytemax
Этот @IdClass объявляет два свойства и должен переопределять метод «equals» и «hascode». Может быть, это поможет кому-то другому;). – Cytemax