【问题标题】:grails : org.hibernate.MappingException: Association references unmapped class: java.util.Setgrails:org.hibernate.MappingException:关联引用未映射的类:java.util.Set
【发布时间】:2015-03-19 15:00:41
【问题描述】:

任何熟悉以下错误的人? 我正在使用带有 Grails 2.4.4 的休眠 4+

这是整个错误日志:

|Loading Grails 2.4.4
|Configuring classpath
.
|Environment set to development
.................................
|Packaging Grails application
...........
|Compiling 1 source files
.........................
|Running Grails application
Error |
2015-03-19 16:54:11,496 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: java.util.Set
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: java.util.Set
    Line | Method
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: java.util.Set
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: java.util.Set
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by MappingException: Association references unmapped class: java.util.Set
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Error |
Forked Grails VM exited with error

【问题讨论】:

    标签: hibernate grails grails-orm


    【解决方案1】:

    问题:

    • 我的一个域类在不应该包含大写字母的地方(“Exploits”而不是“exploits”)。

    解决方案:

    旧代码:

    package core
    
    class Scenario {
        String name
    
        static belongsTo = [ Exploit ]
    
        static hasMany = [ Exploits : Exploit ]
    
        static constraints = {
            name nullable: false , maxSize: 32
        }
    }
    

    新代码:

    package core
    
    class Scenario {
        String name
    
        static belongsTo = [ Exploit ]
    
        static hasMany = [ exploits : Exploit ]
    
        static constraints = {
            name nullable: false , maxSize: 32
        }
    }
    

    有效!!

    【讨论】:

      【解决方案2】:

      如果您在嵌入对象中使用 hasMany 之类的集合,也会出现此错误。

      复合元素可能不包含嵌套集合。

      “复合元素”与@Embeddable 对象相同。因此,@Embeddable 对象的集合不可能保存集合。必须将它们提升为 @Entity 对象。

      参考this link

      【讨论】:

        【解决方案3】:

        将我的项目从 Grails 2.3.11 升级到 2.5.4 后,我遇到了同样的问题。事实证明,必须更新的是 spring-security 生成的类 User、Role 和 UserRole。他们有过时的 getter 和 setter,现在被解释为 bean 属性。

        【讨论】:

          【解决方案4】:

          我遇到了类似的异常,但命名是正确的。

          问题是两个数据源使用 - 用于读取和写入副本。

          该问题的解决方法是添加以下内容:

          static mapping = {
              datasource 'ALL'
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2022-01-15
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-03-07
            • 1970-01-01
            • 2010-12-06
            • 1970-01-01
            相关资源
            最近更新 更多