-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: many to one mapping list problem
PostPosted: Wed Sep 26, 2007 12:21 pm 
Newbie

Joined: Wed Sep 26, 2007 12:05 pm
Posts: 1
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.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="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.java
Code:
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.java
Code:
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.xml
Code:
<?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:(((


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.