i need help with hibernate mapping one-to-many i don´t know why this is 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() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getCalle() {
return calle;
}
public void setCalle(String calle) {
this.calle = calle;
}
public int getNumero() {
return numero;
}
public void setNumero(int numero) {
this.numero = numero;
}
public List<Persona> getHabitantes() {
return habitantes;
}
public void setHabitantes(List<Persona> habitantes) {
this.habitantes = habitantes;
}
@Override
public String toString() {
return "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() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getNombre() {
return nombre;
}
public void setNombre(long nombre) {
this.nombre = nombre;
}
@Override
public String toString() {
return "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 is the 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 from 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/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
jun 21, 2014 6:11:51 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from 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/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
ERROR en la inicialización de la SessionFactory: org.hibernate.InvalidMappingException: Unable to read XML
Exception in thread "main" java.lang.NullPointerException
at dao.DireccionDao.traerListaRubros(DireccionDao.java:128)
at prueba.prueba.main(prueba.java:12)
if anyone can help me with that i´m so grateful thanks!
Exception in thread "main" java.lang.NullPointerException at dao.DireccionDao.traerListaRubros(DireccionDao.java:128)What happens at line 128 ofDireccionDao? - Jim Garrison