Pessoal,
Eu estou tentando fazer o maperamento de uma hieraquia de classes utilizando a especificao EJB3 com o hibernate.
A situação é a seguinte, eu tenho um Super Classe que se chama Usuario(Id, nome, login etc) e duas outras Sub Classes, Professor(Id, professor_usario) e Aluno(Id, aluno_usuario, matricula).
Estou tentado fazer o mapeamento e depois relalizar um inserção, porem esta ocorrendo erros em relação a primaria key(Ids) e Foreign keys(professor_usuario e aluno_usuario)
Eu mapei da seguinte maneira;
@Entity
@Table(name="USUARIO")
@Inheritance(strategy=InheritanceType.JOINED)
@TableGenerator(name = "USUARIO_GEN", table = "GENERATOR_ID", pkColumnName = "ID", valueColumnName = "VALOR", pkColumnValue = "USUARIO", allocationSize = 1)
public class Usuario {
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "USUARIO_GEN")
protected Integer ID;
(...)
@Entity
@Table(name="PROFESSOR")
@PrimaryKeyJoinColumn(name="PROFESSOR_USUARIO")
@TableGenerator(name = "PROFESSOR_GEN", table = "GENERATOR_ID", pkColumnName = "ID", valueColumnName = "VALOR", pkColumnValue = "PROFESSOR", allocationSize = 1)
public class Professor extends Usuario{
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "PROFESSOR_GEN")
private Integer ID;
O erro eh o seguinte:
BUG 12-04 09:33:25,446 (Ejb3Column.java:bind:161) -Binding column ID unique false
DEBUG 12-04 09:33:25,446 (AnnotationBinder.java:processElementAnnotations:1153) -ID is an id
Exception in thread “main” java.lang.ExceptionInInitializerError
Caused by: javax.persistence.PersistenceException: org.hibernate.AnnotationException: Unable to define/override @Id(s) on a subclass:
Quando eu comento a linha
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "PROFESSOR_GEN")
private Integer ID;
da classe professor a execução segue, mas logo a frete ocorre o seguinte erro:
Caused by: java.sql.BatchUpdateException: Unknown column ‘professor_ID’ in ‘field list’
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1093)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:851)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
… 16 more
O que pode ser pessoal
Vlw!