-->
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: empty maps for returnMaps() on many-to-many associations
PostPosted: Thu Jun 17, 2004 5:47 am 
Newbie

Joined: Mon Dec 01, 2003 12:41 pm
Posts: 12
Location: Aix en Provence, France
Dear All,

I am having Problem with returnMaps function for many-to-many associations.

The following code never returns the map with the "dv" alias :
(though it works ok if I transform it into a one-to-many association)

crit = session.createCriteria(Product.class).add(
Expression.eq("id", _idProduct));
List list = crit.createCriteria("divis", "dv")
.add(Expression.like("libl", "Div%"))
.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
.list();

Iterator iter = list.iterator();
listDivis = new ArrayList();
while (iter.hasNext())
{
Map map = (Map) iter.next();
pro = (Product) map.get(Criteria.ROOT_ALIAS);
listDivis.add(map.get("dv"));
}

the iter contains the right number of rows which are the number of Divi Objects found with the "divis" link.
Moreover hibernate does hydrate all the right beans.
It seems that the "dv" map is just not referenced in the ouput list.
any Idea ?

Thanks for all

_________________
Gauthier P.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 10:03 am 
Newbie

Joined: Mon Dec 01, 2003 12:41 pm
Posts: 12
Location: Aix en Provence, France
After investigation in the code
This behaviour COULD NOT WORK with Hibernate since some code has not yet been done
Ths missing code should re-order the alias with the order of the maps
in : net.sf.hibernate.loader.CriteriaLoader.java.

I made a path which does the trick for my usecases but it's not generic ...


protected String generateTableAlias(String className, int n, String path, boolean isLinkTable) {
if (!isLinkTable) {
String userDefinedAlias = criteria.getAlias(path);
if (userDefinedAlias!=null) {
// modif Gauthier Peel
int position;
if(aliases.size()==0)
{
position = 0;
}else
{
position = aliases.size() -1;
}
aliases.add(position, userDefinedAlias); //very dodgy: depends upon the superclass not reordering things!
return userDefinedAlias;
}
}
String generatedAlias = super.generateTableAlias(className, n, path, isLinkTable);
aliases.add(generatedAlias);
return generatedAlias;
}



instead of the original :


protected String generateTableAlias(String className, int n, String path, boolean isLinkTable) {
if (!isLinkTable) {
String userDefinedAlias = criteria.getAlias(path);
if (userDefinedAlias!=null) {
aliases.add(userDefinedAlias); //very dodgy: depends upon the superclass not reordering things!
return userDefinedAlias;
}
}
String generatedAlias = super.generateTableAlias(className, n, path, isLinkTable);
aliases.add(generatedAlias);

If someone could tell me if this feature is in progress ?

_________________
Gauthier P.


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.