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: Criteria for a One-to-Many association through a Map
PostPosted: Wed Aug 31, 2005 12:41 pm 
Newbie

Joined: Wed Aug 31, 2005 11:20 am
Posts: 13
Hi there.

I have 2 class :
Priority
PriorityDescription

There is a relation One-To-Many between Priority (One) and PriorityDescription (Many).

Here is what Priority contains :
Long id
Short level
String code
Map<String, PriorityDescription> description

Here is what PriorityDescription contains :
Long id
String languageCode
String value
Priority priority

We have a map of PriorityDescription wich key is set on languageCode (languageCode is simply the iso language code, ex: fr, en, sp,...)

Now I am trying to perform a find by example with some additionnal criteria to navigate associations. Everything works fine, but when I try to perform a find by example with PriorityDescription values I have some problem.

If I translate what I need in an SQL Query, it goes like this :

SELECT *
FROM Priority
INNER JOIN PriorityDescription fr ON fr.priority_id = Priority.id
INNER JOIN PriorityDescription en ON en.priority_id = Priority.id
WHERE (fr.languageCode = 'fr' and fr.value = 'Priorité 1')
AND (en.languageCode = 'en' and en.value = 'Priority 1')

I have 2 different PriorityDescription that has some values and must be used to filter my search. I have tried something like the following code to represent this :

Criteria crit = s.createCriteria(Priority.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

crit.createCriteria("description", "fr")
.add(Example.create(frPriorityDescription)
.enableLike(MatchMode.ANYWHERE)
.ignoreCase()
);
crit.createCriteria("description", "en")
.add(Example.create(enPriorityDescription)
.enableLike(MatchMode.ANYWHERE)
.ignoreCase()
);

But it gaves me the following error :

org.hibernate.QueryException: duplicate association path: description
at org.hibernate.loader.criteria.CriteriaQueryTranslator.createAssociationPathCriteriaMap(CriteriaQueryTranslator.java:138)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:80)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:58)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1310)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
at com.netappsid.erp.dao.base.BasePriorityDAO.findByExample(BasePriorityDAO.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.netappsid.erp.services.beans.LoaderBean.findByExample(LoaderBean.java:68)
at com.netappsid.client.utils.ActionsManager.action_load(ActionsManager.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.netappsid.client.gui.components.Action.actionPerformed(Action.java:113)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at com.jidesoft.plaf.basic.BasicJideButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.netappsid.client.gui.components.Action.actionPerformed(Action.java:113)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at com.jidesoft.plaf.basic.BasicJideButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Transaction not active
at org.hibernate.ejb.TransactionImpl.rollback(TransactionImpl.java:41)
at com.netappsid.client.naming.NAIDTransactionManager.resetContext(NAIDTransactionManager.java:64)
at com.netappsid.erp.services.beans.LoaderBean.findByExample(LoaderBean.java:72)
at com.netappsid.client.utils.ActionsManager.action_load(ActionsManager.java:117)
... 30 more


I guess I am not using Criteria correctly. Can someone please help me on that one.

Thanks a lot in advance

Francois Archambault

Hibernate version:3.1beta1


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.