-->
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: set mapping
PostPosted: Mon Nov 21, 2005 3:04 pm 
Newbie

Joined: Fri Nov 11, 2005 12:34 pm
Posts: 18
Hi,

I have a bidirectional many-to-many mapping.

On one side collection of entities A is mapped to entity B collection.
I am using <set> mapping in my hbm.xml because I don't need indexed column.

I sort the order of entites A by using order-by attribute, and it is crucial that the order is perserved.

Can I use <set> in my mapping file, and java.util.List in my java class?

MB


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 5:32 pm 
Newbie

Joined: Thu Nov 17, 2005 7:06 pm
Posts: 10
I believe so. Someone else please correct me if I am wrong. You can do a simple check.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 10:32 pm 
Newbie

Joined: Fri Nov 11, 2005 12:34 pm
Posts: 18
Hi, thanks for reply.

Actually I couldn't (yet at least).
The exception is:
java.lang.ClassCastException: java.util.ArrayList
at org.hibernate.type.SetType.wrap(Lorg/hibernate/engine/SessionImplementor;Ljava/lang/Object;)Lorg/hibernate/collection/PersistentCollection;(SetType.java:36)
at org.hibernate.event.def.WrapVisitor.processArrayOrNewCollection(Ljava/lang/Object;Lorg/hibernate/type/CollectionType;)Ljava/lang/Object;(WrapVisitor.java:83)
at org.hibernate.event.def.WrapVisitor.processCollection(Ljava/lang/Object;Lorg/hibernate/type/CollectionType;)Ljava/lang/Object;(WrapVisitor.java:50)
at org.hibernate.event.def.AbstractVisitor.processValue(Ljava/lang/Object;Lorg/hibernate/type/Type;)Ljava/lang/Object;(AbstractVisitor.java:104)
at org.hibernate.event.def.WrapVisitor.processValue(I[Ljava/lang/Object;[Lorg/hibernate/type/Type;)V(WrapVisitor.java:97)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues([Ljava/lang/Object;[Lorg/hibernate/type/Type;)V(AbstractVisitor.java:58)
at org.hibernate.event.def.AbstractSaveEventListener.visitCollectionsBeforeSave(Ljava/io/Serializable;[Ljava/lang/Object;[Lorg/hibernate/type/Type;Lorg/hibernate/engine/SessionImplementor;)Z(AbstractSaveEventListener.java:281)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(Ljava/lang/Object;Ljava/io/Serializable;Lorg/hibernate/persister/entity/EntityPersister;ZLjava/lang/Object;Lorg/hibernate/engine/SessionImplementor;)Ljava/io/Serializable;(AbstractSaveEventListener.java:222)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(Ljava/lang/Object;Ljava/io/Serializable;Lorg/hibernate/persister/entity/EntityPersister;ZLjava/lang/Object;Lorg/hibernate/engine/SessionImplementor;)Ljava/io/Serializable;(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;Lorg/hibernate/engine/SessionImplementor;)Ljava/io/Serializable;(AbstractSaveEventListener.java:95)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(Lorg/hibernate/event/SaveOrUpdateEvent;)Ljava/io/Serializable;(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(Lorg/hibernate/event/SaveOrUpdateEvent;)Ljava/io/Serializable;(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(Lorg/hibernate/event/SaveOrUpdateEvent;)Ljava/io/Serializable;(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(Lorg/hibernate/event/SaveOrUpdateEvent;)Ljava/io/Serializable;(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(Lorg/hibernate/event/SaveOrUpdateEvent;)Ljava/io/Serializable;(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(Ljava/lang/String;Ljava/lang/Object;)Ljava/io/Serializable;(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(Ljava/lang/Object;)Ljava/io/Serializable;(SessionImpl.java:476)

Any ideas?

Thanks

MB


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 4:16 am 
Regular
Regular

Joined: Thu Oct 27, 2005 8:06 am
Posts: 55
Location: München, Germany
The explanation might be in the Hibernate reference, p 87, paragraph starting "If your table doesn't have an index column, and you still wish to use List as the property type..."

However, from your description, I don't see why you need Hibernate to know about the association at all. Your way of preserving the order by an order-by indicates that you always read the collection elements using an SQL statement you wrote yourself. Letting Hibernate fetch the associated elements wouldn't use your order-by clause, so your ordering wouldn't be preserved.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 7:53 am 
Newbie

Joined: Fri Nov 11, 2005 12:34 pm
Posts: 18
i must be blind :)


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.