hibernate在创建sessionFactory时需要很长时间

时间:2014-03-24 03:32:52

标签: hibernate

我写了一个简单的程序来保存一个对象。在hibernate中运行相同的结果需要很长时间才能创建会话工厂。以下是输出......

5 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.2-Final
53 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.2-Final
61 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
73 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
88 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
380 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
396 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
396 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
650 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
664 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
890 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.manyToMany.model.Dog
1007 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.manyToMany.model.Dog on table DOG
1171 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.manyToMany.model.Person
1172 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.manyToMany.model.Person on table PERSON
1452 [main] INFO org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
1471 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
1471 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
1472 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
1488 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/blog
1488 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=kempa, password=****}

我的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.password"></property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/blog</property>
        <property name="hibernate.connection.username">kempa</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.pool_size">1</property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">create</property>

        <mapping class="com.manyToMany.model.Dog" />
        <mapping class="com.manyToMany.model.Person" />

    </session-factory>
</hibernate-configuration>

1 个答案:

答案 0 :(得分:-1)

我也面临同样的问题。但我修好了

使用下面显示的DTD

1)你的hibernate.cfg.xml看起来应该是这样的

<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE
hibernate-configuration PUBLIC
         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
         "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration> ... </hibernate-configuration>

2)你的hibernate类映射应该是这样的

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> ... </hibernate-mapping>