java吧 关注:1,292,181贴子:12,822,262
  • 38回复贴,共1

【hibernate】最新版的hibernate4.3.4出现的一个问题!

只看楼主收藏回复



IP属地:四川1楼2014-03-30 16:01回复
    Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
    这是为什么?


    IP属地:四川本楼含有高级字体2楼2014-03-30 16:09
    收起回复
      2025-12-22 15:15:30
      广告
      不感兴趣
      开通SVIP免广告
      设置hibernate.dialect了吗?


      4楼2014-03-30 16:17
      收起回复
        设置了的!
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>


        IP属地:四川本楼含有高级字体5楼2014-03-30 16:18
        收起回复
          这是获得sessionFactory
          public SessionFactory getSession() {
          Configuration cfg = new Configuration();
          return cfg.buildSessionFactory(new StandardServiceRegistryBuilder().build());
          }
          这是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>
          <!-- Database connection settings -->
          <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
          <property name="connection.url">jdbc:mysql://localhost/hibernate</property>
          <property name="connection.username">root</property>
          <property name="connection.password">123456</property>
          <!-- JDBC connection pool (use the built-in) -->
          <!-- <property name="connection.pool_size">1</property> -->
          <!-- SQL dialect -->
          <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
          <!-- Enable Hibernate's automatic session context management -->
          <property name="current_session_context_class">thread</property>
          <!-- Disable the second-level cache -->
          <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
          <!-- Echo all executed SQL to stdout -->
          <property name="show_sql">true</property>
          <!-- 格式化SQL语句 -->
          <property name="format_sql">true</property>
          <!-- Drop and re-create the database schema on startup -->
          <property name="hbm2ddl.auto">update</property>
          <!-- <mapping class="com.suse.edu.model.Group"/>
          <mapping resource="com/suse/edu/model/User.hbm.xml"/> -->
          <mapping class="com.suse.edu.model.Student"/>
          <mapping class="com.suse.edu.model.Question"/>
          <mapping class="com.suse.edu.model.Answer"/>
          </session-factory>
          </hibernate-configuration>


          IP属地:四川6楼2014-03-30 16:26
          收起回复
            Configuration configuration = new Configuration().configure();
            ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
            SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
            Session session = sessionFactory.openSession();
            session.beginTransaction();
            session.getTransaction().commit();
            session.close();
            sessionFactory.close();
            亲测可用,4.3.4.Final。你再试试吧。


            7楼2014-03-30 17:20
            收起回复
              追新版是要付出点代价的!


              8楼2014-08-06 23:03
              收起回复
                <property name="age" column="email" type="int" />
                我这一句话写错了,结果Hibernate4.3就alter 了我的表,新建了一个column,叫email,真是太智能了。


                IP属地:江苏9楼2014-08-17 11:40
                回复
                  2025-12-22 15:09:30
                  广告
                  不感兴趣
                  开通SVIP免广告
                  RDBMS Dialect
                  MySQL org.hibernate.dialect.MySQLDialect
                  MySQL with InnoDB org.hibernate.dialect.MySQLInnoDBDialect
                  MySQL with MyISAM org.hibernate.dialect.MySQLMyISAMDialect
                  MySQL5 org.hibernate.dialect.MySQL5Dialect
                  MySQL5 with InnoDB org.hibernate.dialect.MySQL5InnoDBDialect
                  mysql版本好像需要用不同的dialect,mysql5的需要用的dialect有改动,你上面写得是:
                  <!-- SQL dialect -->
                  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>


                  IP属地:四川10楼2015-02-17 14:15
                  回复