-->
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.  [ 5 posts ] 
Author Message
 Post subject: Many-to-many basic help
PostPosted: Sat Sep 13, 2003 4:51 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 11:02 am
Posts: 20
Location: Montevideo, Uruguay
Hello anyone out there.

I have a basic many to many question.

I have th cat class of the quickstart.

And made a CatPound class. o try to save a collection of cats.

public class CatPound {

private String id;

private Collection cats;

private String name;

....
public CatPound(){
cats = new Vector();
}

------------------------------------

the Catpound.hbm.xml goes:

<hibernate-mapping>
<class name="hbtest.CatPound" table="CATPOUND">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="id" type="string" unsaved-value="null" >
<column name="CATP_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="name">
<column name="NAME" sql-type="varchar(16)" not-null="true"/>
</property>
<!-- <property name="sex"/>
<property name="weight"/>-->
<set name="cats" table="catpound-cat" cascade="all" lazy="true">
<key>
<column name="CATPID" not-null="true"/>
</key>
<many-to-many class="hbtest.Cat">
<column name="CATID" not-null="true"/>
</many-to-many>
</set>

</class>
</hibernate-mapping>

-----------------

When the SessionFactory is initiali<ing I get the following exception:

INFO: Mapping collection: CatPound.cats -> catpound_cat
java.lang.NoClassDefFoundError: org/odmg/DCollection
at java.lang.ClassLoader.defineClass0(Native Method)



-----------------

Ideas? hits? Are very much apreciated.

Thanks
Mata


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 13, 2003 4:56 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If you want to map associations, the odmg.jar is a required library.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 13, 2003 5:12 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 11:02 am
Posts: 20
Location: Montevideo, Uruguay
Oh! That was easy enough. Thanks for the swift answer.

But I now get a:

java.lang.ClassCastException
at net.sf.hibernate.type.SetType.wrap(SetType.java:27)
at net.sf.hibernate.impl.SessionImpl.wrap(SessionImpl.java:2519)
at net.sf.hibernate.impl.SessionImpl.wrap(SessionImpl.java:2459)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:708)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1202)
at com.b4.hbtest.ClaseParaProbar.SalvarColecciones(ClaseParaProbar.java:104)


when performing the save.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 13, 2003 5:20 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A Vector is not a Set.

Please use the interface types for collection valued properties and an implementation that is more "modern":

Set cats = new HashSet();

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 13, 2003 5:27 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 11:02 am
Posts: 20
Location: Montevideo, Uruguay
Ok, sorry. It's been a couple of years since I didn't work with Java. I guess old habbits do die hard.

I was meaning to avoid this, but I guess I have to look into Java Collections again.

thaks for your quick answers


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

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.