【问题标题】:Hibernate Mapping Exception, working with annotations休眠映射异常,使用注释
【发布时间】:2019-06-10 12:05:28
【问题描述】:

我正在尝试使用 Hibernate 和 MySQL。我创建了一些测试实例并试图保存它们,但遇到了

hibernate.MappingException: 未知实体: ....Category.

Category 类如下所示:

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(name = "categories_table")
public class Category {

    @Id
    @Column
    private String code;
    @Column
    private String name;
    @OneToMany(mappedBy = "category")
    private Set<Addon> addons;

hibernate.cfg.xml 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost/xa04?createDatabaseIfNotExist=true</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.connection.password">password</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.hbm2ddl.auto">update</property>
 </session-factory>
</hibernate-configuration>

【问题讨论】:

标签: java mysql hibernate jpa orm


【解决方案1】:

您需要使用包含完全限定类名或通配符的适当映射来更新您的配置:

<hibernate-configuration>
 <session-factory>
  ...
  <mapping class="com.mypackage.Category" />
 </session-factory>
</hibernate-configuration>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 2013-01-12
    • 1970-01-01
    相关资源
    最近更新 更多