映射迁移:Hibernate 4到Hibernate 5

时间:2018-03-06 03:54:08

标签: java hibernate hibernate-mapping

我的应用程序正常运行Hibernate 4。

Maven依赖:

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.11.Final</version>
    </dependency>

实体:

import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Date;
import java.util.Set;

@Entity
@Table(name = "USERS")
public class User implements Serializable{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Generated(GenerationTime.INSERT)
    @Column(name = "ID")
    private int userId;
    @Column(name = "USERNAME")
    private String userName;
    @Column(name = "FIRSTNAME")
    private String firstName;
    @Column(name = "LASTNAME")
    private String lastName;
         ...

Hibernate配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/MY_USERS</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.pool_size">1</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.archive.autodetection">class, hbm</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="hibernate.jdbc.batch_size">20</property>
        <mapping class="com.mk.hibernate.demo.User"/>
        <mapping class="com.mk.hibernate.demo.Book"/>
    </session-factory>
</hibernate-configuration>

查询:

 public List<User> getUsers(){

        Session session = sessionFactory.openSession();
        List<User> users = session.createQuery(" from User").list();
        session.close();
        return users;
    }

工作正常。但是当我升级hibernate版本时

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.13.Final</version>
        </dependency>

没有进一步的变化,我开始得到以下异常:

  

org.hibernate.hql.internal.ast.QuerySyntaxException:用户不是   映射

可能的原因是什么?

0 个答案:

没有答案