課程
/后端開發(fā)
/Java
/Hibernate初探之單表映射
myEclipse如何配置Hibernate配置文件?
2018-07-03
源自:Hibernate初探之單表映射 1-7
正在回答
在項目的src下新建一個.xml 名稱為hibernate.cfg.xml?
代碼如下(我的是mysql+hibernate5.3)版本不同 寫法都不同 看看你用的都是啥版本
注:其中我的數(shù)據(jù)庫是hibernate 賬號root 密碼為空 你要改成你自己的
<mapping resource="com/student/Student.hbm.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>
? ? <!-- 第一部分: 配置數(shù)據(jù)庫信息 必須的 -->
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate?useSSL=false&serverTimezone=UTC</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<!-- 第二部分: 配置hibernate信息? 可選的-->
<!-- 輸出底層sql語句 -->
<property name="hibernate.show_sql">true</property>
<!-- 輸出底層sql語句格式 -->
<property name="hibernate.format_sql">true</property>
<!-- hibernate幫創(chuàng)建表,需要配置之后?
update: 如果已經(jīng)有表,更新,如果沒有,創(chuàng)建
-->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 配置數(shù)據(jù)庫方言
在mysql里面實現(xiàn)分頁 關(guān)鍵字 limit,只能使用mysql里面
在oracle數(shù)據(jù)庫,實現(xiàn)分頁rownum
讓hibernate框架識別不同數(shù)據(jù)庫的自己特有的語句
<property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<!-- 第三部分: 把映射文件放到核心配置文件中 必須的-->
<mapping resource="com/student/Student.hbm.xml"/>
? ? </session-factory>
</hibernate-configuration>
艾米麗宏 提問者
舉報
Java持久化框架Hibernate入門教程,掌握Hibernate基本概念
1 回答myeclipse上配置hibernate文件
3 回答hibernate配置文件
1 回答新建hibernate配置文件時報錯。
2 回答Hibernate配置問題
1 回答myEclipse如何安裝Hibernate?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-07-20
在項目的src下新建一個.xml 名稱為hibernate.cfg.xml?
代碼如下(我的是mysql+hibernate5.3)版本不同 寫法都不同 看看你用的都是啥版本
注:其中我的數(shù)據(jù)庫是hibernate 賬號root 密碼為空 你要改成你自己的
<mapping resource="com/student/Student.hbm.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>
? ? <!-- 第一部分: 配置數(shù)據(jù)庫信息 必須的 -->
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate?useSSL=false&serverTimezone=UTC</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<!-- 第二部分: 配置hibernate信息? 可選的-->
<!-- 輸出底層sql語句 -->
<property name="hibernate.show_sql">true</property>
<!-- 輸出底層sql語句格式 -->
<property name="hibernate.format_sql">true</property>
<!-- hibernate幫創(chuàng)建表,需要配置之后?
update: 如果已經(jīng)有表,更新,如果沒有,創(chuàng)建
-->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 配置數(shù)據(jù)庫方言
在mysql里面實現(xiàn)分頁 關(guān)鍵字 limit,只能使用mysql里面
在oracle數(shù)據(jù)庫,實現(xiàn)分頁rownum
讓hibernate框架識別不同數(shù)據(jù)庫的自己特有的語句
-->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<!-- 第三部分: 把映射文件放到核心配置文件中 必須的-->
<mapping resource="com/student/Student.hbm.xml"/>
? ? </session-factory>
</hibernate-configuration>