Saturday, 15 March 2014

java - org.hibernate.InvalidMappingException: Unable to read XML -



java - org.hibernate.InvalidMappingException: Unable to read XML -

i need help hibernate mapping one-to-many don´t know why wrong

public class direccion { private long id; private string calle; private int numero; private list<persona> habitantes; public direccion(){ } public direccion(long id, string calle, int numero, list<persona> habitante) { super(); this.id = id; this.calle = calle; this.numero = numero; this.habitantes = habitante; } public long getid() { homecoming id; } public void setid(long id) { this.id = id; } public string getcalle() { homecoming calle; } public void setcalle(string calle) { this.calle = calle; } public int getnumero() { homecoming numero; } public void setnumero(int numero) { this.numero = numero; } public list<persona> gethabitantes() { homecoming habitantes; } public void sethabitantes(list<persona> habitantes) { this.habitantes = habitantes; } @override public string tostring() { homecoming "direccion [id=" + id + ", calle=" + calle + ", numero=" + numero + ", habitantes=" + habitantes + "]"; } }

another class:

public class persona { private long id; private long nombre; public persona(){ } public persona(long id, long nombre) { super(); this.id = id; this.nombre = nombre; } public long getid() { homecoming id; } public void setid(long id) { this.id = id; } public long getnombre() { homecoming nombre; } public void setnombre(long nombre) { this.nombre = nombre; } @override public string tostring() { homecoming "persona [id=" + id + ", nombre=" + nombre + "]"; } }

the mapping

<?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="datos.direccion" table="direccion"> <id column="id" name="id"> <generator class="identity"> </generator> </id> <property column="calle" name="calle" type="string" /> <property name="numero" column="numero" type="int" /> <set name="habitantes" table="persona" inverse="true" lazy="true" fetch="select"> <key> <column name="idpersona" not-null="true" /> </key> <one-to-many class="datos.persona" /> </class> </hibernate-mapping>

another mapping:

<?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="datos.persona" table="persona"> <id column="id" name="id"> <generator class="identity"/> </id> <property column="nombre" name="nombre" type="string" /> <many-to-one name="direccion" class="datos.direccion" column="idpersona" not-null="true"/> </set> </class> </hibernate-mapping>

hibernate configuration

<?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="connection.driver_class">com.mysql.jdbc.driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/repasohibernate</property> <property name="connection.username">root</property> <property name="connection.password">root</property> <property name="connection.pool_size">1</property> <property name="dialect">org.hibernate.dialect.mysqldialect</property> <property name="show_sql">true</property> <!-- en true muestra hql en consola --> <!--mapeo entidades --> <mapping resource="mapeos/persona.hbm.xml" /> <mapping resource="mapeos/direccion.hbm.xml" /> </session-factory> </hibernate-configuration>

this error:

jun 21, 2014 6:11:51 pm org.hibernate.annotations.common.version <clinit> info: hcann000001: hibernate commons annotations {4.0.1.final} jun 21, 2014 6:11:51 pm org.hibernate.version logversion info: hhh000412: hibernate core {4.1.9.final} jun 21, 2014 6:11:51 pm org.hibernate.cfg.environment <clinit> info: hhh000206: hibernate.properties not found jun 21, 2014 6:11:51 pm org.hibernate.cfg.environment buildbytecodeprovider info: hhh000021: bytecode provider name : javassist jun 21, 2014 6:11:51 pm org.hibernate.cfg.configuration configure info: hhh000043: configuring resource: /hibernate.cfg.xml jun 21, 2014 6:11:51 pm org.hibernate.cfg.configuration getconfigurationinputstream info: hhh000040: configuration resource: /hibernate.cfg.xml jun 21, 2014 6:11:51 pm org.hibernate.internal.util.xml.dtdentityresolver resolveentity warn: hhh000223: recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. utilize namespace http://www.hibernate.org/dtd/ instead. refer hibernate 3.6 migration guide! jun 21, 2014 6:11:51 pm org.hibernate.cfg.configuration addresource info: hhh000221: reading mappings resource: mapeos/persona.hbm.xml jun 21, 2014 6:11:51 pm org.hibernate.internal.util.xml.dtdentityresolver resolveentity warn: hhh000223: recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. utilize namespace http://www.hibernate.org/dtd/ instead. refer hibernate 3.6 migration guide! error en la inicialización de la sessionfactory: org.hibernate.invalidmappingexception: unable read xml exception in thread "main" java.lang.nullpointerexception @ dao.direcciondao.traerlistarubros(direcciondao.java:128) @ prueba.prueba.main(prueba.java:12)

if can help me i´m grateful thanks!

if mapping 1 direccion many personas, one-to-many mapping. means persona has many-to-one relationship direccion. have list<persona> variable under direccion class. need have direccion class variable persona class.

here illustration of hibernate configuration xml. http://www.mkyong.com/hibernate/hibernate-one-to-many-relationship-example/

java hibernate hibernate-mapping

No comments:

Post a Comment