miguelAngelOjeda / hibernate-generic-dao

Automatically exported from code.google.com/p/hibernate-generic-dao
0 stars 0 forks source link

Nested properties is not working for addFilterIn and Collection of objects #71

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Helo,

Thanks for the very useful hibernate generic DAO, your code is.

I'm getting a little problem working on nested attributes and collection of 
mapped objects.

=== Classses ===
public class User implements Serializable {

    @Id
    private long id;

    @ManyToMany(fetch = LAZY)
    @JoinTable(
            name="user_group_user",
            schema="users",
            joinColumns = @JoinColumn(
                    name="userId", 
                    referencedColumnName = "id"), 
            inverseJoinColumns = @JoinColumn(
                    name="groupId", 
                    referencedColumnName = "id")
    )
    @OrderBy
    Set<UserGroup> groups;
}

public class ServiceRequest implements {

    @ManyToOne
    @JoinColumn(name="assignedUserId", referencedColumnName = "id")
    @Fetch(FetchMode.JOIN)
    private User assignedUser;
}
==================

This code is working fine:

Search s = new Search();        
List<Long> uids = new ArrayList<Long>();
uids.add(1l);
uids.add(2l);
s.addFilterIn("assignedUser.id", uids);

This code is not working

Search s = new Search();        
List<UserGroup> groups = new ArrayList<UserGroup>();
groups.add(new UserGroup(1));
groups.add(new UserGroup(2));
s.addFilterIn("assignedUser.groups", groups);

Error: 

Caused by: java.lang.IllegalArgumentException: Property path 
'assignedUser.groups' invalid for type com.sarbarian.itsm.entity.ServiceRequest
    at com.trg.search.jpa.JPAAnnotationMetadataUtil.get(JPAAnnotationMetadataUtil.java:24)
    at com.trg.search.BaseSearchProcessor.prepareValue(BaseSearchProcessor.java:707)
    at com.trg.search.BaseSearchProcessor.filterToQL(BaseSearchProcessor.java:451)
    at com.trg.search.BaseSearchProcessor.generateWhereClause(BaseSearchProcessor.java:413)
    at com.trg.search.BaseSearchProcessor.generateQL(BaseSearchProcessor.java:111)
    at com.trg.search.jpa.JPASearchProcessor.search(JPASearchProcessor.java:88)

Question: What should do I do?

Thanks !!

Davi.

Original issue reported on code.google.com by bal...@gmail.com on 8 Oct 2010 at 6:23

GoogleCodeExporter commented 9 years ago
Try this:

Search s = new Search();        
List<UserGroup> groups = new ArrayList<UserGroup>();
groups.add(new UserGroup(1));
groups.add(new UserGroup(2));
s.addFilterSome("assignedUser.groups", Filter.in("", groups));

Because groups is a collection, the normal filters do not work. You have to use 
SOME, ALL, or NONE filters to operate on collections.

Original comment by dwolvert on 9 Oct 2010 at 3:04

GoogleCodeExporter commented 9 years ago
Hi, thanks for your reply:

I've tried it and I've got the same:

Search(class com.sarbarian.itsm.entity.ServiceRequest)[first: -1, page: -1, 
max: -1] {
 resultMode: AUTO,
 disjunction: false,
 fields: {  },
 filters: {
  some `assignedUser.groups` {`` in (ArrayList {com.sarbarian.user.entity.UserGroup@16af3e6, com.sarbarian.user.entity.UserGroup@16af3e6})}
 },
 sorts: {  }
}
16:59:38,859 ERROR [[Resteasy]] Servlet.service() for servlet Resteasy threw 
exception
org.jboss.resteasy.spi.UnhandledException: javax.ejb.EJBException: 
java.lang.IllegalArgumentException: Property path 'assignedUser.groups' invalid 
for type com.sarbarian.itsm.entity.ServiceRequest

Original comment by bal...@gmail.com on 9 Oct 2010 at 8:02

GoogleCodeExporter commented 9 years ago
Oh, you're using JPA (I should have noticed). Are you using Hibernate's JPA 
implementation? If not, JPA mappings are only partially supported. But that 
still might not be the problem. First see what EQL is really getting spit out.

Set your logging for the category "com.trg.search.jpa.JPASearchProcessor" to 
DEBUG, and check your log to see if the query is messed up. Please paste the 
result here as well. I'm curious to see what's going on.

Another thing to consider is that if you're using JPA 2, you can probably write 
write and implementation of MetadataUtil in a couple of days based using the 
JPA metadata API. That would make the framework fully compatible with any JPA2 
implementation. It would be an extremely useful thing to contribute back to the 
project, and it should solve your problem.

Original comment by dwolvert on 12 Oct 2010 at 2:37

GoogleCodeExporter commented 9 years ago
Hi,

I've created the category but I'm not sure if this is what you want. The only 
entry was:

2010-10-13 07:43:13,203 DEBUG [com.trg.search.jpa.JPASearchProcessor] 
(http-192.168.192.124-8080-2) p1: 1

Unfortunately, I'm using JPA 1. However, I could contribute debugging and 
revising the current implementation for the project. I just would like to know 
wich classes should I have a look or should I take care of.

Cheers, Davi.

Original comment by bal...@gmail.com on 13 Oct 2010 at 11:03

GoogleCodeExporter commented 9 years ago
Oops I forgot to finish what I intended to put in the comment. Also add DEBUG 
for "com.trg.search.BaseSearchProcessor". This logging is found here: 
http://code.google.com/p/hibernate-generic-dao/wiki/Logging. I just added it, 
but forgot to put it all my comment to you.

Original comment by dwolvert on 13 Oct 2010 at 11:15

GoogleCodeExporter commented 9 years ago
Hi, not working yet.

2010-10-14 13:40:21,375 DEBUG [com.trg.search.BaseSearchProcessor] 
(http-192.168.192.124-8080-1) generateQL:
  select _it from com.sarbarian.crm.entity.Site _it where _it.company.id = :p1
2010-10-14 13:40:21,375 DEBUG [com.trg.search.jpa.JPASearchProcessor] 
(http-192.168.192.124-8080-1) p1: 1

However the query present here isn't the marformed query. I'll try to debug the 
code in order to find something and I'll post my findings here.

Cheers,

Davi

Original comment by bal...@gmail.com on 14 Oct 2010 at 4:43

GoogleCodeExporter commented 9 years ago
Is this relevant anymore?

Original comment by pablit...@gmail.com on 14 Jun 2014 at 7:03