生成持久性映射 -> 通过 hibernate 映射不可用 Intellij

Generate persistence mappings -> by hibernate mappings not available Intellij

我是 Hibernate 的新手,我正在尝试创建以下 class,我现在想为其生成休眠映射。

package com.simpleprogrammer;

public class User {

    private int id;
    private String name;
    private int total;
    private int goal;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public int getGoal() {
        return goal;
    }
    public void setGoal(int goal) {
        this.goal = goal;
    }
    public int getTotal() {
        return total;
    }
    public void setTotal(int total) {
        this.total = total;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

当我右键单击 Persistence 时,我希望看到 "Generate Persistence Mappings" -> "By Hibernate Mappings" 可用。但事实并非如此。我只能看到 "By database schema"。有人知道为什么“By Hibernate Mappings 不可用吗?

如果要求或需要,将提供更多信息,我正在学习一个已经过时约 2 年的 pluralsight 课程并使用 Eclipse,只是为了让事情变得更加复杂!

您需要添加:

@Entity 在 class 的开头:

@Entity
public class User {

    @Id
    private int id;
    ...

然后在关闭元素</session-factory>

之前将<mapping class="com.simpleprogrammer.User"/>添加到hibernate.cfg.xml

还请务必将 ID 注释 (@Id) 添加到变量 id。