-->
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 many and collection problem]
PostPosted: Wed Sep 22, 2004 12:46 pm 
Newbie

Joined: Tue Sep 07, 2004 4:39 am
Posts: 4
Hi all,
I got a big problem with a many to many association. I can set a data using my collection but i can't extract one from the database.
the request on the Database is done but nothing appear like if all was empty but the table is full and the request should extract various datas.

Thinks;

Hibernate version:
2.14

Mapping documents:

Quote:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.moi.data">
<class name="ComponentVO" table="components">

<id name="id" column="id" type="int">
<generator class="increment"/>
</id>
<property name="name" column="Name" type="string"/>
<property name="description" column="description" type="string"/>
<property name="productId" column="product_id" type="int"/>
<property name="initialOwner" column="initialowner" type="string"/>
<property name="initialQaContact" column="initialqacontact" type="string"/>

<set name="versions" table="versions_has_components" lazy="true">
<key>
<column name="components_id" not-null="true"/>
</key>
<many-to-many class="com.moi.data.ComponentVersionVO" >
<column name="version_value" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>


Mapping of ComponentVersionVO:

Quote:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="com.moi.data">
<class name="com.moi.data.ComponentVersionVO" table="componentVersions">
<id name="value" column="value" type="string">
<generator class="assigned"/>
</id>
<set name="components" lazy="true" table="versions_has_components">
<key>
<column name="version_value" not-null="true"/>
</key>
<many-to-many class="com.moi.data.ComponentVO">
<column name="components_id" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>





Code between sessionFactory.openSession() and session.close():


Quote:

import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
import java.util.*;
import com.moi.data.*;
public class Test3 {

public static void main(String[] args) {
Transaction tx=null;
Session session=null;
List customer=null;
try{

Configuration cfg = new Configuration();
cfg.addClass(OperatorVO.class);
cfg.addClass(ComponentVersionVO.class);
cfg.addClass(ComponentVO.class);
cfg.addClass(ProductVO.class);
cfg.addClass(VersionVO.class);
cfg.addClass(ProfileVO.class);
SessionFactory factory = cfg.buildSessionFactory();
session = factory.openSession();

Collection products= session.find("from ProductVO where id=2");

Iterator i = products.iterator();
while (i.hasNext()){
ProductVO product=(ProductVO)i.next();
System.out.println(product.getName());
ComponentVO component= (ComponentVO)session.find("from ComponentVO c where id=2").get(0);
System.out.println(component.getName());
Set versions=component.getVersions();
Iterator it= versions.iterator();
while (it.hasNext()){
System.out.println(((ComponentVersionVO)it.next()).getValue());
}

}

session.close();
System.out.println("fin");
}
catch(Exception e){
e.printStackTrace();
}

}


}



Full stack trace of any exception that occurs:
no exception
Name and version of the database you are using:
mysql 3.23
The generated SQL (show_sql=true):
Quote:
18:43:13,550 WARN EhCache:94 - Could not find configuration for net.sf.hibernate.cache.StandardQueryCache. Configuring using the defaultCache settings.
Hibernate: select productvo0_.id as id, productvo0_.name as name, productvo0_.description as descript3_, productvo0_.defaultmilestone as defaultm4_, productvo0_.milestoneurl as mileston5_, productvo0_.disallownew as disallow6_, productvo0_.votesperuser as votesper7_, productvo0_.maxvotesperbug as maxvotes8_, productvo0_.votestoconfirm as votestoc9_ from products productvo0_ where (id=2 )
Hibernate: select operators0_.products_id as products2___, operators0_.operators_id as operator1___, operatorvo1_.id as id0_, operatorvo1_.name as name0_, operatorvo1_.hoster as hoster0_, operatorvo1_.os as os0_ from products_has_operators operators0_ inner join operators operatorvo1_ on operators0_.operators_id=operatorvo1_.id where operators0_.products_id=?
Postcard
Hibernate: select componentv0_.id as id, componentv0_.Name as Name, componentv0_.description as descript3_, componentv0_.product_id as product_id, componentv0_.initialowner as initialo5_, componentv0_.initialqacontact as initialq6_ from components componentv0_ where (id=2 )
atchik.modules.aiimage
Hibernate: select versions0_.components_id as componen2___, versions0_.version_value as version_1___, componentv1_.value as value0_, componentv1_.component_id as componen2_0_ from versions_has_components versions0_ inner join componentVersions componentv1_ on versions0_.version_value=componentv1_.value where versions0_.components_id=?
Hibernate: select componentv0_.id as id, componentv0_.Name as Name, componentv0_.description as descript3_, componentv0_.product_id as product_id, componentv0_.initialowner as initialo5_, componentv0_.initialqacontact as initialq6_ from components componentv0_ where (id=2 )
fin

Debug level Hibernate log excerpt:


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.