Prezados, estou desenvolvendo uma aplicação utilizando hibernate, e agora estou testando porem esta dando erro, segue:
Classe POJO
@Entity
@Table(name = "proprietario")
public class Proprietario {
@IndexColumn(name = "idProprietario_UNIQUE")
@Id
@Column(name = "idProprietario", nullable = false)
private Integer idProprietario;
@Column(name = "proprietarioNome", nullable = false)
private String proprietarioNome;
@Column(name = "numeroArrais", nullable = false)
private String numeroArrais;
@Column(name = "cpf", nullable = false)
private String cpf;
@Column(name = "telefone", nullable = false)
private String telefone;
public Proprietario() {
this.proprietarioNome = null;
this.numeroArrais = null;
this.cpf = null;
this.telefone = null;
this.idProprietario = null;
}
@Override
public String toString() {
return "Proprietario [idProprietario=" + idProprietario + ", proprietarioNome=" + proprietarioNome
+ ", numeroArrais=" + numeroArrais + ", cpf=" + cpf
+ ", telefone=" + telefone + "]";
}
public Integer getidProprietario() {
return idProprietario;
}
public void setidProprietario(Integer idProprietario) {
this.idProprietario = idProprietario;
}
public String getproprietarioNome() {
return proprietarioNome;
}
public void setproprietarioNome(String proprietarioNome) {
this.proprietarioNome = proprietarioNome;
}
public String getArrais() {
return numeroArrais;
}
public void setArrais(String arrais) {
this.numeroArrais = arrais;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
}
Classe de Teste
public class ProprietarioController {
public static void inclusaoDeProprietario(Proprietario registro)
throws Exception {
ProprietarioHibernate proHBR = new ProprietarioHibernate();
if (proHBR.inclui(registro))
System.out.println("Inserido: " + registro);
}
public static void exclusaoDeProprietario(Proprietario registro)
throws Exception {
ProprietarioHibernate proHBR = new ProprietarioHibernate();
if (proHBR.exclui(registro))
System.out.println("Excluído: " + registro);
}
public static void alteracaoDeProprietario(Proprietario registro)
throws Exception {
ProprietarioHibernate proHBR = new ProprietarioHibernate();
if (proHBR.altera(registro))
System.out.println("Alterado: " + registro);
}
public static Proprietario consultaDeProprietario(Proprietario registro)
throws Exception {
ProprietarioHibernate proHBR = new ProprietarioHibernate();
registro = proHBR.consulta(registro);
if (registro.getidProprietario() > 0)
System.out.println("Consulta: " + registro);
return registro;
}
public static void listagemDeProprietario() throws Exception {
ProprietarioHibernate proHBR = new ProprietarioHibernate();
System.out.println("*****Listando Tudo*******");
for (Proprietario p : proHBR.listaTudo())
System.out.println(p);
}
public static void listagemDeProprietario(int inicio, int fim)
throws Exception {
ProprietarioHibernate proHBR = new ProprietarioHibernate();
System.out.println("*****Listando Subconjunto Paginado*******");
for (Proprietario p : proHBR.pagina(inicio, fim))
System.out.println(p);
}
public static void main(String[] args) throws Exception {
Proprietario registro = new Proprietario();
registro.setidProprietario(1);
registro.setproprietarioNome("Jose Antonio");
registro.setArrais("1256897");
registro.setCpf("03668599190");
registro.setTelefone("061-39645985");
inclusaoDeProprietario(registro);
Meu hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/mydb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.max_size">5</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.use_sql_comments">true</property>
<mapping class="br.ucb.pojo.Embarcacao" />
<mapping class="br.ucb.pojo.JetSki" />
<mapping class="br.ucb.pojo.Lancha" />
<mapping class="br.ucb.pojo.Proprietario" />
</session-factory>
</hibernate-configuration>
Erro que esta dando:
01:32:32 INFO [Version ] Hibernate Commons Annotations 3.2.0.Final
01:32:32 INFO [Environment ] Hibernate 3.6.5.Final
01:32:32 INFO [Environment ] hibernate.properties not found
01:32:32 INFO [Environment ] Bytecode provider name : javassist
01:32:32 INFO [Environment ] using JDK 1.4 java.sql.Timestamp handling
01:32:32 INFO [Configuration ] configuring from resource: /hibernate.cfg.xml
01:32:32 INFO [Configuration ] Configuration resource: /hibernate.cfg.xml
01:32:32 WARN [DTDEntityResolver ] recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
01:32:32 INFO [Configuration ] Configured SessionFactory: null
01:32:33 INFO [AnnotationBinder ] Binding entity from annotated class: br.ucb.pojo.Embarcacao
01:32:33 INFO [EntityBinder ] Bind entity br.ucb.pojo.Embarcacao on table embarcacao
01:32:33 INFO [AnnotationBinder ] Binding entity from annotated class: br.ucb.pojo.JetSki
01:32:33 INFO [EntityBinder ] Bind entity br.ucb.pojo.JetSki on table jetski
Exception in thread "main" java.lang.ClassCastException: org.hibernate.mapping.JoinedSubclass cannot be cast to org.hibernate.mapping.RootClass
at org.hibernate.cfg.annotations.PropertyBinder.bind(PropertyBinder.java:209)
at org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:200)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2061)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1856)
at br.ucb.hibernate.ProprietarioHibernate.<init>(ProprietarioHibernate.java:26)
at br.ucb.aplicacao.ProprietarioController.inclusaoDeProprietario(ProprietarioController.java:10)
at br.ucb.aplicacao.ProprietarioController.main(ProprietarioController.java:63)
Alguem sabe me dar uma dica?