【问题标题】:querydsl-sql join查询 dsl-sql 连接
【发布时间】:2015-03-08 15:49:34
【问题描述】:

我是 querydsl 和 sql 的初学者,我需要执行复杂的选择查询 这是我的 qbean 课程

final QBean<SystemPath> systemPathBean = bean(SystemPath.class, systemPath.systemPathId
        , systemPath.path, systemPath.organId
);

final QBean<SecurableItemType> securableItemTypeBean = bean(SecurableItemType.class, securableItemType.all());

final QBean<SecurableItem> securableItemBean = bean(SecurableItem.class, securableItem.securableItemId
  , securableItem.name, securableItem.enabled, securableItem.position, securableItem.uniqueId
  , systemPathBean.as("systemPath")
  , securableItemTypeBean.as("securableItemType")
);

final QBean<RoleSecurableItem> roleSecurableItemBean = bean(RoleSecurableItem.class, bean(SecurableItem.class
  , securableItem.securableItemId, securableItem.position, securableItem.name
  , securableItemBean.as("parent")
  , securableItem.enabled).as("securableItem")
);

final QBean<Role> roleBean = bean(Role.class, role.roleId, role.name
  , role.enabled, role.uniqueId, role.description
  , GroupBy.list(roleSecurableItemBean).as("securableItems")
);

final QBean<UserRole> userRoleBean = bean(UserRole.class, roleBean.as("role"));

final QBean<UserIpAddress> userIpAddressBean = bean(UserIpAddress.class, bean(IpAddress.class
  , ipAddress.ipAddressId, ipAddress.ip
  , bean(IpType.class, ipType.all()).as("ipType")).as("ipAddress"));

final QBean<AppUser> appUserBean = bean(AppUser.class, appUser.userId, appUser.personalCode
  , appUser.firstName, appUser.lastName, appUser.username, appUser.password, appUser.enabled
  , appUser.picture, appUser.organId, appUser.description, appUser.loginTry, appUser.userLocked
  , GroupBy.list(userRoleBean).as("roles")
  , GroupBy.list(userIpAddressBean).as("ipAddresses")
);

这是我的选择查询

return queryFactory
   .from(appUser)
   .fullJoin(appUser._fkuserRole472634, userRole)
   .fullJoin(userRole.fkuserRole820825, role)
   .fullJoin(role._fkroleSecur628757, roleSecurableItem)
   .fullJoin(roleSecurableItem.fkroleSecur233998, securableItem)
   .fullJoin(securableItem.fksecurable177065, systemPath)
   .fullJoin(securableItem.fksecurable353324, securableItemType)
   .fullJoin(appUser._fkuserIpAd409749, userIpAddress)
   .fullJoin(userIpAddress.fkuserIpAd387468, ipAddress)
   .fullJoin(ipAddress.fkipAddress105451, ipType)
   .where(where)
   .transform(GroupBy.groupBy(appUser.userId)
   .list(appUserBean));

但是当我运行代码时会出现这个错误:

created sql: select APP_USER.USER_ID
from SECURITY.APP_USER APP_USER
full join SECURITY.USER_ROLE USER_ROLE
on APP_USER.USER_ID = USER_ROLE.USER_ID
full join SECURITY.ROLE ROLE
on USER_ROLE.ROLE_ID = ROLE.ROLE_ID
full join SECURITY.ROLE_SECURABLE_ITEM ROLE_SECURABLE_ITEM
on ROLE.ROLE_ID = ROLE_SECURABLE_ITEM.ROLE_ID
full join SECURITY.SECURABLE_ITEM SECURABLE_ITEM
on ROLE_SECURABLE_ITEM.SECURABLE_ITEM_ID = SECURABLE_ITEM.SECURABLE_ITEM_ID
full join SECURITY.SYSTEM_PATH SYSTEM_PATH
on SECURABLE_ITEM.SECURABLE_ITEM_ID = SYSTEM_PATH.SYSTEM_PATH_ID
full join SECURITY.SECURABLE_ITEM_TYPE SECURABLE_ITEM_TYPE
on SECURABLE_ITEM.SECURABLE_ITEM_TYPE_CODE = SECURABLE_ITEM_TYPE.CODE
full join SECURITY.USER_IP_ADDRESS USER_IP_ADDRESS
on APP_USER.USER_ID = USER_IP_ADDRESS.USER_ID
full join SECURITY.IP_ADDRESS IP_ADDRESS
on USER_IP_ADDRESS.IP_ADDRESS_ID = IP_ADDRESS.IP_ADDRESS_ID
full join SECURITY.IP_TYPE IP_TYPE
on IP_ADDRESS.IP_TYPE_CODE = IP_TYPE.CODE
where APP_USER.USERNAME = ? and APP_USER.USER_LOCKED = ? and APP_USER.ENABLED = ? and     APP_USER.LOGIN_TRY <= ?
ERROR [2015-01-10 10:40:50,015] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error     handling a request: d0767b57da188c25
! java.lang.IllegalArgumentException: argument type mismatch

【问题讨论】:

    标签: sql join querydsl


    【解决方案1】:

    尝试检查where 表达式的每个值是否与bean 上定义的类型完全匹配。例如:如果LOGIN_TRY 已被定义为整数,则检查APP_USER.LOGIN_TRY &lt;= ? 的值是否为整数

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多