已采納回答 / 回聲0
把我敲得分享給你create table grade( gid int primary key; gname varchar(20) not null; gdesc varchar(50)?);create table students( sid int primary key; sname varchar(20) not null; sex char(2), gid int?);alter table students add constraint fk_students_gid foreign key...
2016-09-23
Session session= sessionFactory.getCurrentSession();
Session session= sessionFactory.openSession();
兩個效果一樣。不過get更好一些,一是可以綁定線程增加安全,二是自動提交關閉。
只需要在配置文件中添加:
<property name="hibernate.current_session_context_class">thread</property>
Session session= sessionFactory.openSession();
兩個效果一樣。不過get更好一些,一是可以綁定線程增加安全,二是自動提交關閉。
只需要在配置文件中添加:
<property name="hibernate.current_session_context_class">thread</property>
2016-09-23
單表操作的那個老師的半本太老了,這個老師的半本太超前了,
可以這樣。版本號3.3.2這是改進版本的開始半本。算是比較穩定的。
SessionFactory factory= configuration.buildSessionFactory();
可以這樣。版本號3.3.2這是改進版本的開始半本。算是比較穩定的。
SessionFactory factory= configuration.buildSessionFactory();
2016-09-23
已采納回答 / 程序猿和攻城獅
流程是這樣的:首先,添加hibernate的支持類和oracle數據庫驅動的jar包,然后配置hibernate的配置文件hibernate.cfg.xml,在配置文件里指定方言為oracle,驅動類為oracle的驅動類,其余不變,然后自建一個數據庫,再根據此數據庫創建持久化類以及各自的映射文件hbm.xml,在映射文件里配置映射關系,比如一對多或者多對一,最后在hibernate的配置文件里指定映射文件的路徑,這就ok了。以上是手動操作,當然myeclipse可以自動生成,在第五章的課程總結里,依葫蘆...
2016-09-23
// hibernate 5.2.2 獲得會話過程
StandardServiceRegistry ssr=new StandardServiceRegistryBuilder().configure().build();
// 創建會話工廠
sessionFactory=new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
// 獲得會話
session=sessionFactory.getCurrentSession();
StandardServiceRegistry ssr=new StandardServiceRegistryBuilder().configure().build();
// 創建會話工廠
sessionFactory=new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
// 獲得會話
session=sessionFactory.getCurrentSession();
2016-09-18
// hibernate5.2.2 獲得session
StandardServiceRegistry ssr=new StandardServiceRegistryBuilder().configure().build();
sessionFactory=new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
session=sessionFactory.getCurrentSession();
transaction=session.beginTransaction();
StandardServiceRegistry ssr=new StandardServiceRegistryBuilder().configure().build();
sessionFactory=new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
session=sessionFactory.getCurrentSession();
transaction=session.beginTransaction();
2016-09-18