Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2268

SQL Generation with query using IN element

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.2.0
    • None
    • jdbc, kernel, sql
    • None

    Description

      Hi all, I've been staring at a problem for the last 12 hours with a JPQL query that appears to be parsing incorrectly. There are three tables, a permissions table with a n-n relation to a role table, in turn with an n-n relation to a users table. These n-n relations are created with default options of the @ManyToMany annotation and I have added them below for completeness.The intent of the query is to get all permissions for a user by username: select p from Permission p, IN(p.roles) r, IN(r.users) u where u.username = :name.

      No errors are generated, but the SQL emitted to the log has not been parsed or transformed at all. (This may be correct, I've been fortunate enough so far not to have to look at the SQL generated by OpenJPA).

      Debugging into OpenJPA, it appears that the generated query is "select permission p where username='?'", which obviously will not return anything.

      I'm still debugging this (having gotten down to the level of the jflex code), but it's my first time going deep on OpenJPA like this so things are going slow. I'll post updates here, but if anyone sees this and has ideas of where to look first (no matter how small), it may be a great help.

      Thank you1

      {code name=Permission.java}

      @Entity
      public class Permission

      { ... @ManyToMany(mappedBy="permissions",targetEntity=Role.class) private Set<Role> roles; } {code} {code name=Role.java}

      @Entity
      public class Role

      { ... @ManyToMany(mappedBy="users",targetEntity=User.class) private Set<User> users; } {code} {code name=User.java}

      @Entity
      public class User

      { ... @Column private String username; } {code}

      Attachments

        Activity

          People

            Unassigned Unassigned
            topping Brian Topping
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: