-->
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: HQL Projection Issue with Set Using AliasToBeanResultTrans~
PostPosted: Thu Jun 26, 2014 1:12 pm 
Newbie

Joined: Thu Jun 26, 2014 1:05 pm
Posts: 1
So basically, I am having a problem with Hibernate HQL Projection using the AliasToBeanResultTransformer, the result I am trying to get isn't being mapped properly to the bean.
The HQL query that I am using is this:

Code:
select entity.categoryTypes as categoryTypes from nz.co.doltech.ims.server.entities.IncidentEntity entity where (entity.id = :id105019)

I want to get the CategoryType's from the IncidentEntity based on its join relationship. This works fine when I'm not attempting to use any transformer on it. categoryTypes is a Set and the transformer keeps trying to check the Method's parameter types and fails because instead of finding a CategoryTypeEntity it finds a java.util.Set as if its trying to map a single CategoryTypeEntity into the categoryTypes field. I would have thought that because its a Set it would pull the data out as a Set and then try map it to the categoryTypes field. Apparently not though.

Code:
@javax.persistence.Entity(name = "incidents")
@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
public class IncidentEntity implements Entity {

    ...

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "incident_categorytype", joinColumns = {
            @JoinColumn(name = "incident_id", nullable = false, updatable = false) },
        inverseJoinColumns = {
            @JoinColumn(name = "categorytype_id", nullable = false, updatable = false)
    })
    private Set<CategoryTypeEntity> categoryTypes = new HashSet<CategoryTypeEntity>();

    ...

    public Set<CategoryTypeEntity> getCategoryTypes() {
        return categoryTypes;
    }
    public void setCategoryTypes(Set<CategoryTypeEntity> categoryTypes) {
        this.categoryTypes = categoryTypes;
    }
}

Here is the call I make:

Code:
Query query = session.createQuery("select entity.categoryTypes as categoryTypes from nz.co.doltech.ims.server.entities.IncidentEntity entity " +
                                  "where (entity.id = :id105019)")

query.setResultTransformer(Transformers.aliasToBean(IncidentEntity.class));

return query.list();

The exceptions I get are:

Code:
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of nz.co.doltech.ims.server.entities.IncidentEntity.categoryTypes
...
Caused by: java.lang.IllegalArgumentException: argument type mismatch

And the hibernate log message is:

Code:
Jun 27, 2014 12:32:11 AM org.hibernate.property.BasicPropertyAccessor$BasicSetter set
SEVERE: IllegalArgumentException in class: nz.co.doltech.ims.server.entities.IncidentEntity, setter method of property: categoryTypes
Jun 27, 2014 12:32:11 AM org.hibernate.property.BasicPropertyAccessor$BasicSetter set
SEVERE: expected type: java.util.Set, actual value: nz.co.doltech.ims.server.entities.CategoryTypeEntity

Using Hibernate 3.6.10
I am using second-level caching with ehcache setup using Spring.

Can anyone see what is going on here? It really doesn't seem like normal behavior, perhaps I have done something wrong. Would appreciate any help I can get!

UPDATE: This is strange, not directly related to the issue. When I have hibernates use_query_cache property set to true I keep getting the projection result as null in the AliasToBeanResultTransformer (then the result returns as null (or [null, null, null] depending on how many are returned. I think this might be a bug? In regards to the issue at hand, when I remove the result transformer it returns 3 CategoryTypeEntites as expected, but not in a Set<>. When its added I get one CategoryTypeEntity that's being processed in the Transformers transformTuple method. Really confused about both of these issues.

Cheers, Ben

Stackoverflow Post: http://stackoverflow.com/questions/24431693/hibernate-hql-projection-issue-with-set-using-aliastobeanresulttransformer


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.