简体   繁体   English

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

[英]Generate persistence mappings -> by hibernate mappings not available Intellij

I am brand new to Hibernate and I am trying have created the following class, which I now want to generate the hibernate mappings for. 我是Hibernate的新手,正在尝试创建以下类,现在我想为其生成hibernate映射。

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;
    }
}

When I right-click on Persistence I expect to see "Generate Persistence Mappings" -> "By Hibernate Mappings" to be available. 当我右键单击Persistence时,我希望看到“ Generate Persistence Mappings”->“ By Hibernate Maps”可用。 But it is not. 但事实并非如此。 All I can see is "By database schema". 我只能看到“按数据库模式”。 Does anybody know why "By Hibernate Mappings is not available? 有人知道为什么“无法使用休眠映射吗?

Will supply more information if requested or required, I am following a pluralsight course which is approx 2 years out of date and using Eclipse, just to make things even more complex! 如果需要或需要的话,将提供更多信息,我将遵循大约2年后使用Eclipse的多元视野课程,以使事情变得更加复杂!

You need to add: 您需要添加:

@Entity at start of class: 在课程开始时@Entity

@Entity
public class User {

    @Id
    private int id;
    ...

Then add <mapping class="com.simpleprogrammer.User"/> to hibernate.cfg.xml before closing of element </session-factory> 然后在关闭元素</session-factory>之前,将<mapping class="com.simpleprogrammer.User"/>hibernate.cfg.xml

also med sure that you add ID annotation ( @Id ) to variable id. 还请确保将ID批注( @Id )添加到变量id。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM