Hi, I have small problem with list/save/persist operations in 1:n mapping.
I have 1:n mapping between Item and Attribute classes.
Item.hbm.xml
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 package="logic" default-lazy="false">
<class name="Item" table="item" lazy="false">
<id name="id" column="id" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="type" column="type" type="java.lang.String" />
</class>
</hibernate-mapping>
Attribute.hbm.xmlCode:
<?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 package="logic" default-lazy="false">
<class name="Attribute" table="attribute">
<id name="id" column="id" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="type" column="type" type="java.lang.String" />
<property name="value" column="value" type="java.lang.String" />
<many-to-one name="item" class="Item" column="idItem"></many-to-one>
</class>
</hibernate-mapping>
Item.javaCode:
package logic;
import java.util.Collection;
import java.util.List;
public class Item extends BasicObject{
private String name;
private String type;
private List<Attribute> attribute=new java.util.ArrayList<Attribute>();;
// private Collection relation;
public Item(){
}
public List getAttribute() {
return attribute;
}
public void setAttribute(List attribute) {
this.attribute = attribute;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
Attribute.javaCode:
package logic;
public class Attribute extends BasicObject{
private String name;
private String type;
private String value;
private Item item;
public Attribute() {
}
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
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="connection.url">jdbc:mysql://localhost/Nefer</property>
<property name="connection.username">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">dub054</property>
<property name="hibernate.show_sql">true</property>
<!-- mapping files -->
<mapping resource="database/config/Item.hbm.xml" />
<mapping resource="database/config/Attribute.hbm.xml" />
</session-factory>
</hibernate-configuration>
Now, when I want to list Items - I will obtain them, but without their collections of attributes(there are empty). I think that I missed something very important, but I really do not know what:((
I know, that it is the small problem, but I'm on forums/internet whole day and I can not find solution:(((