Olá Pessoal.
Então estou tentando fazer uma herança no hibernate mas esta dando erro, a herança é por union mas com Annotation, abaixo os fontes:
[code]
package struts.teste.heranca;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class SuperClasse {
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
package struts.teste.heranca;
import javax.persistence.Entity;
@Entity
public class SubClasse extends SuperClasse{
private String nome;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}[/code]
O XML
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:mysql://localhost/struts</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="log4j.org.properties">info</property>
<!-- pool de conexoes -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">180</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<mapping class="struts.teste.heranca.SuperClasse" />
<mapping class="struts.teste.heranca.SubClasse" />
</session-factory>
</hibernate-configuration>
AnnotationConfiguration conf = new AnnotationConfiguration();
conf.configure();
Session session = conf.buildSessionFactory().openSession();
Transaction tran = session.beginTransaction();
tran.begin();
SubClasse sub = new SubClasse();
sub.setNome("GABRIEL");
session.save(sub);
tran.commit();
session.close();
Agora o Erro
Exception in thread "main" org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: struts.teste.heranca.SuperClasse
at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:67)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at struts.teste.heranca.GeraBanco.main(GeraBanco.java:15)
Quem poder me ajudr fico grato, falow
PS: a tabela no banco de dado o hibernate esta gerando, mas, na hora de persistir não.