【问题标题】:Domain classes relations query not working after upgrade grails from 1.3.7 to 2.2.2将 grails 从 1.3.7 升级到 2.2.2 后域类关系查询不起作用
【发布时间】:2013-12-17 19:39:47
【问题描述】:

我正在将我的 grails 应用程序从 grails 版本 1.3.7 升级到 2.2.2。除了这个之外,我使大部分代码都能正常工作。相同的代码在 grails 1.3.7 中工作,但在 grails 2.2.2 中停止工作并出现错误。请帮忙。这是导致问题的类。 域类 User、UserConfig 和服务类 UserService。

public class User implements Serializable {
  String id
  ...
  static hasMany = [userConfigs:UserConfig]

  static mapping = {
    version false
    table 'c_user'
    id column: 'id'
  }

}
public class UserConfig implements Serializable
{
    UserProfile profile
    String genesysUserId

    static belongsTo = [user: User]

    static mapping = {
        version false
        table 'sp_user_config'
        id composite:['user', 'profile']
        user column: 'user_id'
        profile column: 'profile_id', lazy: false
    }
}

public class UserService {

    boolean transactional = true

    def getUserList(groupIdList) {

        def userList = User.list()

        userList.findAll() { user ->
            user.userConfigs?.find() { userConfig ->
                        groupIdList.contains(userConfig?.profile?.group?.id)

            }
        }
    }
}

我上课了; java.lang.IllegalArgumentException 消息:参数类型不匹配 在

行的 UserService.groovy 类中

user.userConfigs?.find() { userConfig-> 和线userList.findAll() { user->

如果我将“List userConfigs”添加到用户域类中

public class User implements Serializable {
  String id
  List<UserConfig> userConfigs
  ...
  static hasMany = [userConfigs:UserConfig]

  static mapping = {
    version false
    table 'c_user'
    id column: 'id'
  }

}

我得到了类:java.sql.SQLException 消息:ORA-00904:“USERCONFIG0_”。“USER_CONFIGS_IDX”:来自同一类 UserService 和同一行代码的无效标识符。

这是新版grails的issue还是hibernate issue?

【问题讨论】:

  • 请发布完整的堆栈跟踪和服务代码。
  • 你在服务方法中使用@TypeChecked吗?
  • 我没有使用@TypeChecked注解。

标签: hibernate grails


【解决方案1】:

第一件事,也是最简单的,如果你将孩子作为一个列表(在这种情况下是列表),hibernate 期望在表中看到一个索引列,因此它知道将每个孩子放在列表中的哪个位置。那里的 SQL 异常似乎表明了这一点。

至于第一个问题,它似乎不是休眠问题,因为您只是在迭代已经加载的对象。您没有包含 UserProfile ,因此不确定它是否与该对象有关。

我的第一步是在这些闭包中加入一些日志记录,看看发生了什么。或者,如果您是调试器爱好者,请使用它。

【讨论】:

  • 有趣的是,UserService中的同一段代码可以在Grails Console中成功运行。是
  • 很有趣的发现,UserService类中的同一段代码也能成功,没有问题。那么这可能是tomcat插件问题吗?
  • 注释掉“List userConfigs”这一行,看看是否可行。或者,在 oracle 抱怨的列中添加
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-29
  • 1970-01-01
  • 1970-01-01
  • 2012-05-26
相关资源
最近更新 更多