Good Nigth People!
I have a problem during the mapping of my classes. I use .hbm.xml with composite-id. In ther first use, the mapping works correctly, but after i modify the other classes, the execution of mapping show this error.
Quote:
run:
13/05/2011 16:44:42 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
13/05/2011 16:44:42 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
13/05/2011 16:44:42 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
13/05/2011 16:44:42 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
13/05/2011 16:44:42 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: hibernateMtCad.cfg.xml
13/05/2011 16:44:42 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: hibernateMtCad.cfg.xml
13/05/2011 16:44:42 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : Persistencia/hbm/AvalUf.hbm.xml
13/05/2011 16:44:42 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: Persistencia.AvalUf -> avaluf
13/05/2011 16:44:42 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : Persistencia/hbm/AvalEmpresa.hbm.xml
13/05/2011 16:44:42 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: Persistencia.AvalEmpresa -> avalempresa
13/05/2011 16:44:42 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : Persistencia/hbm/AvalMsg.hbm.xml
13/05/2011 16:44:42 org.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: XML InputStream(20) The content of element type "composite-id" must match "(meta*,(key-property|key-many-to-one)+)".
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Could not parse mapping document from resource Persistencia/hbm/AvalMsg.hbm.xml
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at Persistencia.util.HibernateUtil.<clinit>(HibernateUtil.java:36)
at Persistencia.dao.AvalMsgDAO.getRecords(AvalMsgDAO.java:215)
Follow bellow my .hbm.xml Mapping.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Persistencia.AvalMsg" schema="mtcad" table="avalmsg">
<composite-id class="Persistencia.pk.AvalMsgPK" name="mensagemPK">
<key-property column="RegAnalis" name="RegAnalis" type="java.lang.String"/>
<key-property column="NrValidac" name="NrValidac" type="java.lang.String"/>
<generator class="assigned"></generator>
</composite-id>
<property name="criticidade" type="java.lang.Integer">
<column name="criticidade"/>
</property>
<property name="erp" type="java.lang.String">
<column name="erp"/>
</property>
<property name="DescrAnalis" type="java.lang.String">
<column name="DescrAnalis"/>
</property>
<property name="DadosAnali" type="java.lang.String">
<column name="DadosAnali"/>
</property>
<property name="PropostaSolucao" type="java.lang.String">
<column name="PropostaSolucao"/>
</property>
</class>
</hibernate-mapping>
Follow bellow my classCode:
package Persistencia;
import Persistencia.pk.AvalMsgPK;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import util.ErrorMessage;
public class AvalMsg implements Serializable{
private AvalMsgPK mensagemPK;
private int criticidade;
private String erp;
private String DescrAnalis;
private String DadosAnali;
private String PropostaSolucao;
private AvalMsg(){}
public AvalMsg(String NrValidac, String RegAnalis, String erp, Integer criticidade, String DescrAnalis, String DadosAnali, String PropostaSolucao) {
this.mensagemPK = new AvalMsgPK(NrValidac, RegAnalis);
this.criticidade = criticidade;
this.erp = erp;
this.DescrAnalis = DescrAnalis;
this.DadosAnali = DadosAnali;
this.PropostaSolucao = PropostaSolucao;
}
public AvalMsg(String NrValidac, String RegAnalis, Integer criticidade) {
this.mensagemPK = new AvalMsgPK(NrValidac, RegAnalis);
this.criticidade = criticidade;
}
public String getErp() {
return erp;
}
public void setErp(String erp) {
this.erp = erp;
}
public AvalMsgPK getMensagemPK() {
return mensagemPK;
}
public void setMensagemPK(AvalMsgPK mensagemPK) {
this.mensagemPK = mensagemPK;
}
public int getCriticidade() {
return criticidade;
}
public void setCriticidade(int criticidade) {
this.criticidade = criticidade;
}
public String getDescrAnalis() {
return DescrAnalis;
}
public void setDescrAnalis(String descrAnalis) {
DescrAnalis = descrAnalis;
}
public String getDadosAnali() {
return DadosAnali;
}
public void setDadosAnali(String dadosAnali) {
DadosAnali = dadosAnali;
}
public String getPropostaSolucao() {
return PropostaSolucao;
}
public void setPropostaSolucao(String propostaSolucao) {
PropostaSolucao = propostaSolucao;
}
}
Follow my PK ClassCode:
package Persistencia.pk;
import java.io.Serializable;
public class AvalMsgPK implements Serializable{
private String NrValidac;
private String RegAnalis;
private AvalMsgPK(){}
public AvalMsgPK(String nrVal, String RegAnalis){
super();
this.NrValidac = nrVal;
this.RegAnalis = RegAnalis;
}
public String getNrValidac() {
return this.NrValidac;
}
public String getRegAnalis() {
return this.RegAnalis;
}
public void setNrValidac(String nrValidac) {
this.NrValidac = nrValidac;
}
public void setRegAnalis(String regAnalis) {
this.RegAnalis = regAnalis;
}
}
Follow the Hibernate .cfg.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!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.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/mtcad</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">validate</property>
<mapping resource="Persistencia/hbm/AvalUf.hbm.xml"/>
<mapping resource="Persistencia/hbm/AvalEmpresa.hbm.xml"/>
<mapping resource="Persistencia/hbm/AvalMsg.hbm.xml"/>
<mapping resource="Persistencia/hbm/Aval_aliq_ipi.hbm.xml"/>
<mapping resource="Persistencia/hbm/AvalNcm.hbm.xml"/>
<mapping resource="Persistencia/hbm/Aval_uf_icms.hbm.xml"/>
</session-factory>
</hibernate-configuration>
What's Happens?