Hibernate:AnnotationConfiguration实例需要使用... error

Val*_*lva 9 eclipse hibernate hibernate-tools

我用这种方式构建我的HibernateUtil:

public class HibernateUtil {

        private static final SessionFactory sessionFactory;

        static {
            try { 
                // Create the SessionFactory from standard (hibernate.cfg.xml) config file.
                sessionFactory = new Configuration().configure().buildSessionFactory();

            } catch (Throwable ex) {
                // Log the exception. 
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }

        public static SessionFactory getSessionFactory() {
            return sessionFactory;
        }
}
Run Code Online (Sandbox Code Playgroud)

因此,当我尝试在Eclipse中的HQL编辑器中执行HQL命令(使用Hibernate Tools)时,会出现以下错误: 在此输入图像描述 为什么会这样?它不会通过ConfigureAnnotation更改AnnotationConfiguration?

UPDATE

<?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.password"><password></property>
        <property name="hibernate.connection.url">jdbc:mysql://<hostname>:3306/<schema></property>
        <property name="hibernate.connection.username">root</property>
        <!-- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> -->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- SQL -->
        <property name="hibernate.format_sql">true</property>
        <property name="hibernate.show_sql">true</property>
        <!-- C3P0 -->
        <property name="hibernate.c3p0.acquire_increment">2</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.timeout">180</property>
        <property name="hibernate.c3p0.idle_test_period">100</property>
        <!-- Classes -->
        <mapping class="com.suaparte.pojo.Area" />
    </session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Iva*_*van 12

如果您遇到该错误,并且您使用的是hibernate版本> = 4.0,则问题可能出在Hibernate Console配置中.

试着去:

运行 - >运行配置

并打开您创建的配置,在主选项卡上将Type从Core更改为Annotations.这是一个截图: 在此输入图像描述


Kar*_*put 8

只需将Configuration()更改为AnnotationConfiguration()