【问题标题】:IntelliJ: Cannot resolve symbol 'GenericGenerator'IntelliJ:无法解析符号“GenericGenerator”
【发布时间】:2020-04-01 05:43:43
【问题描述】:

据本文https://vladmihalcea.com/hibernate-and-uuid-identifiers/ 我想为我的班级生成休眠 UUID。 IntelliJ 说'无法解析'GenericGenerator''。它也不识别 GenericGenerator 导入。

Entity.java:

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

import org.hibernate.annotations.GenericGenerator;

@MappedSuperclass
public abstract class Entity {
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @Column(columnDefinition = "CHAR(32)")
    @Id
    protected String id;

    public BaseEntity() {
    }
}

我的 build.gradle 中有这些依赖项:

compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
runtime group: 'org.hibernate', name: 'hibernate-core', version: '5.4.9.Final'

【问题讨论】:

    标签: java hibernate jpa gradle


    【解决方案1】:

    由于@GenericGenerator 注释是hibernate-core 的一部分,我将检查依赖项是否已在 IntelliJ 模块中正确注册。有时通过build.gradle 重新导入项目会有所帮助。另外我会将dependency typeruntime 更改为compile,因为在编译时也需要依赖项。

    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.9.Final'
    

    【讨论】:

      【解决方案2】:

      尝试将“org.hibernate”依赖的范围更改为“编译”:

      compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.9.Final'
      

      有关 Gradle 范围的更多信息:Difference between compile and runtime configurations in Gradle

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-12
        • 1970-01-01
        • 1970-01-01
        • 2019-04-23
        • 2019-02-21
        • 2019-03-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多