小编use*_*478的帖子

Hibernate抛出奇怪的错误:未映射类

这是错误

org.hibernate.hql.ast.QuerySyntaxException: Payment is not mapped [select p from Payment p]
Run Code Online (Sandbox Code Playgroud)

我不明白为什么会抛出这个错误,这个类应该被映射,因为我会简要地向你展示.我有一个非常基本的配置,如下所示:http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/ch01.html

我试图将映射定义添加到hibernate.cfg.xml中,我也尝试以编程方式添加它.他们都没有工作.有谁能告诉我,我在这里失踪了什么?(这不是我第一次整理Hibernate项目)

这是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.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/paymentsdatabase</property>
    <property name="hibernate.connection.username">xxx</property>
    <property name="hibernate.connection.password">xxx</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>

    <property name="hibernate.hbm2ddl.auto">create</property>

    <!--  <mapping class="com.lsyh.swati.zk.model.Payment"/> -->
  </session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)

数据库连接工作正常,我已经测试过了

这是我的HibernateUtil中的静态初始化程序

static {
    try {

        // Create the SessionFactory from standard (hibernate.cfg.xml) 
        // config file.
        sessionFactory = new AnnotationConfiguration()
            .addPackage("com.lsyh.swati.zk.model")
            .addAnnotatedClass(Payment.class)
            .configure().buildSessionFactory();
    } catch (Throwable ex) { …
Run Code Online (Sandbox Code Playgroud)

java orm hibernate jpa hibernate-mapping

27
推荐指数
2
解决办法
8万
查看次数

标签 统计

hibernate ×1

hibernate-mapping ×1

java ×1

jpa ×1

orm ×1