九色国产,午夜在线视频,新黄色网址,九九色综合,天天做夜夜做久久做狠狠,天天躁夜夜躁狠狠躁2021a,久久不卡一区二区三区

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Hibernate4.3.x Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

          如下錯誤

                Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set。


                        今天沒事看看新的hibernate-core-4.3.10.Final   看來官方文檔。

                      

public class Person {

   public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPassword() { return password; } public void setPassword(int password) { this.password = password; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; }   private Integer id;   private String name;   private int password;   private Date birthday;}



<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC 	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"	"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><!-- 持久化映射文件(將java對象映射到數據庫表) --><hibernate-mapping>   <class name="com.it.hibernate.pojo.Person" table="t_person">     <id name="id">        <generator class="native"></generator>     </id>     <property name="name" column="t_name" length="12"/>     <property name="password" length="6"/>     <property name="birthday" />   </class> </hibernate-mapping>
官方獲取sessionfactory
public class HibernateUtil {    private static final SessionFactory sessionFactory = buildSessionFactory();    private static SessionFactory buildSessionFactory() {        try {            // Create the SessionFactory from hibernate.cfg.xml            return new Configuration().configure().buildSessionFactory(			    new StandardServiceRegistryBuilder().build() );        }        catch (Throwable ex) {            // Make sure you log the exception, as it might be swallowed            System.err.println("Initial SessionFactory creation failed." + ex);            throw new ExceptionInInitializerError(ex);        }    }    public static SessionFactory getSessionFactory() {        return sessionFactory;    }}
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>	<session-factory>		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>		<property name="hibernate.connection.url">jdbc:mysql:///hibernate_db</property>		<property name="hibernate.connection.username">root</property>		<property name="hibernate.connection.password">123456</property>		<!-- 數據庫方言 加五提高速度 -->		<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>		<!-- 展現sql -->		<property name="show_sql">true</property>		<!-- 格式化sql -->		<property name="hibernate.format_sql">true</property>		<!-- 自動創(chuàng)建sql create 每次執(zhí)行都都要先刪除表再創(chuàng)建表 update 沒有就創(chuàng)建表 有就直接插入 -->		<property name="hibernate.hbm2ddl.auto">update</property>		<mapping resource="com/it/hibernate/pojo/Person.hbm.xml" />	</session-factory>

</hibernate-configuration>


測試類
public class PersonTest {	public static void main(String[] args) {		  SessionFactory factory =HibernateUtil.getSessionFactory();		  Session session = factory.openSession();		  Transaction tx =   session.beginTransaction();		  Person p = new Person();		  p.setName("MOMO");		  p.setPassword(123456);		  p.setBirthday(new Date());		  session.save(p);		  tx.commit();		  session.close();	} }
如下錯誤
Initial SessionFactory creation failed.org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.it.hibernate.utils.HibernateUtil2.buildSessionFactory(HibernateUtil2.java:21)
at com.it.hibernate.utils.HibernateUtil2.<clinit>(HibernateUtil2.java:9)
at com.it.hibernate.pojo.test.PersonTest.main(PersonTest.java:14)
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at com.it.hibernate.utils.HibernateUtil2.buildSessionFactory(HibernateUtil2.java:16)
... 2 more
修改獲取sessionFactory的公用方法
public class HibernateUtil {    private static final SessionFactory sessionFactory = buildSessionFactory();    private static SessionFactory buildSessionFactory() {        try {            // 從 hibernate.cfg.xml 創(chuàng)建SessionFactory        	        	Configuration cfg = new Configuration().configure();        	StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()            .applySettings(cfg.getProperties()).build();            return cfg.buildSessionFactory(            		serviceRegistry);        }        catch (Throwable ex) {            System.err.println("Initial SessionFactory creation failed." + ex);            throw new ExceptionInInitializerError(ex);        }    }    public static SessionFactory getSessionFactory() {        return sessionFactory;    }}
修改完就可以順利插入數據。 有個疑問是官方給錯了?還是我其他地方有問題有問題呢! 但是我改了sessionfactory獲取方式就好了呀!求大神指點。

    private static final SessionFactory sessionFactory = buildSessionFactory();    private static SessionFactory buildSessionFactory() {        try {            // Create the SessionFactory from hibernate.cfg.xml            return new Configuration().configure().buildSessionFactory(			    new StandardServiceRegistryBuilder().build() );        }        catch (Throwable ex) {            // Make sure you log the exception, as it might be swallowed            System.err.println("Initial SessionFactory creation failed." + ex);            throw new ExceptionInInitializerError(ex);        }    }    public static SessionFactory getSessionFactory() {        return sessionFactory;    }}
本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現有害或侵權內容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
hibernate入門案例代碼的優(yōu)化
Hibernate 5.0.2加載hibernate.cfg.xml時mapping不生效
Hibernate中SessionFactory配置
Hibernate工作原理
[Solved] HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’
hibernate 三種查詢方式源碼跟蹤及總結
更多類似文章 >>
生活服務
熱點新聞
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服