gpt4 book ai didi

java - Hibernate 不想映射 hibernate.cfg.xml 中的类

转载 作者:行者123 更新时间:2023-12-02 04:40:15 25 4
gpt4 key购买 nike

我有一个 User 类,它是 Entity。当我试图在 hibernate.cfg.xml 中映射它时

<mapping class="com.igorgorbunov3333.entities.User"/> 

得到一个错误:

Exception in thread "main" org.hibernate.MappingException: Unknownentity: com.igorgorbunov3333.entities.User

但是当我以编程方式映射类 User 时它工作正常。

configuration.addAnnotatedClass(User.class);

这是什么原因?

我的实体类:

package com.igorgorbunov3333.entities;

import javax.persistence.*;


/**
* Created by Игорь on 01.07.2016.
*/

@Entity
@Table(name="user")
public class User {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

private String name;

private String email;

private String password;

public int getId() {
return id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}

最佳答案

尝试使用 4.3.6.Final 版本的 hibernate。你使用什么 hibernate 版本?使用 5.2.1.Final 我看到了同样的问题。通过更改 hibernate 版本来解决。

回答 https://forum.hibernate.org/viewtopic.php?f=1&t=1043461&p=2489997&hilit=hibernate.cfg.xml#p2489997

关于java - Hibernate 不想映射 hibernate.cfg.xml 中的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38168701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com