-->
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.  [ 2 posts ] 
Author Message
 Post subject: Ternary Associations
PostPosted: Mon Aug 02, 2004 7:22 pm 
Newbie

Joined: Mon Jun 14, 2004 5:16 pm
Posts: 16
Location: New York
I have 3 tables:
tbl_movie
Code:
id
name
...



tbl_theater
Code:
id
name
adress
...


tbl_event
Code:
id
movie_id
even_id
price
date
....



and I have 3 corresponding classes, Movie, Theater and Event

What I'm trying to do is to make sure
everytime I load a Movie, it comes with set of theaters it plays in, and vice versa for Theater.

So basically, everytime a Movie is loaded, find the mapping entries in the
tbl_event and through those records load the Theater objects.

In Theater I have:
Code:
List movies


and Theater.hbm.xml contains:
Code:
<bag
            name="movies"
            table="tbl_event"
            lazy="false"
            inverse="false"
            cascade="none"
        >

              <key
                  column="theater_id"
              >
              </key>

              <element
                  column="movie_id"
                  type="Movie"
                  not-null="false"
                  unique="false"
              />

        </bag>


and in Movie similarly:
Code:
List theaters


and the Movie.hbm.xml contains:
Code:
       
<bag
            name="theaters"
            table="tbl_event"
            lazy="false"
            inverse="false"
            cascade="none"
        >

              <key
                  column="movie_id"
              >
              </key>

              <element
                  column="theater_id"
                  type="Venue"
                  not-null="false"
                  unique="false"
              />

        </bag>


When I try to load the Theaters, say, by their zipcode:
Code:
Query query = session.createQuery("from " + Theater.class.getName()
                    + " venue where theater.address.postcode like :zip "
                    + " order by theater.address.postcode, " + " theater.name");
query.setParameter(...,...);


I get the following error:
net.sf.hibernate.type.SerializationException: could not deserialize
at net.sf.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:197)
at net.sf.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:220)
at net.sf.hibernate.type.SerializableType.fromBytes(SerializableType.java:73)
at net.sf.hibernate.type.SerializableType.get(SerializableType.java:38)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
at net.sf.hibernate.collection.AbstractCollectionPersister.readElement(AbstractCollectionPersister.java:363)
at net.sf.hibernate.collection.Bag.readFrom(Bag.java:75)
at net.sf.hibernate.loader.Loader.readCollectionElement(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:219)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:915)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:890)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:83)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3264)
at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:336)
at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3119)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)

Code:
Aug 2, 2004 5:57:58 PM WARNING: Unable to run query: net.sf.hibernate.type.SerializationException: could not deserialize



All classes implement Serializable and have default constructors...

What am I doing wrong here?

Thanks in advance,
Cagan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 4:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Read the documentation and use a proper association mapping and not an element mapping.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.