課程
/后端開發
/Java
/Hibernate初探之單表映射
照著打,出現錯誤
2016-11-29
源自:Hibernate初探之單表映射 1-11
正在回答
最主要的報錯信息呢。。給我的給你參考
public void test1(){?? ??? ?Configuration configuration = new Configuration().configure();?? ??? ?//創建配置對象?? ??? ??? ??? ?ServiceRegistry st = new ServiceRegistryBuilder().?? ??? ??? ??? ?applySettings(configuration.getProperties()).buildServiceRegistry();?? ??? ?//創建服務注冊對象?? ??? ??? ??? ?SessionFactory sf = configuration.buildSessionFactory(st);?? ??? ?//創建會話工廠對象?? ??? ??? ??? ?Session session = sf.openSession();?? ??? ?//打開會話?? ??? ??? ??? ?Transaction tx = session.beginTransaction();?? ??? ?//打開事務?? ??? ??? ??? ?Book book = new Book();?? ??? ?//生成學生對象?? ??? ??? ??? ?session.save(book);?? ??? ?//保存對象進入數據庫?? ??? ??? ??? ?tx.commit();?? ??? ?//提交事務?? ??? ??? ??? ?session.close();?? ??? ?//關閉會話?? ??? ??? ??? ?sf.close();?? ??? ?//關閉會話工廠?? ?}
謝謝拉、、下次提問最好給出錯誤信息。。很多像我們這樣剛剛學的都是配置文件出錯的。。
qq__5248 提問者
舉報
Java持久化框架Hibernate入門教程,掌握Hibernate基本概念
1 回答照著老師代碼打的結果出現Type mismatch: cannot convert from ServiceRegistryBuilder to ServiceRegistry錯誤
2 回答這里為什么會錯???照著老師的代碼打的
9 回答一步一步照著老師,為什么測試不成功
1 回答hibernate錯誤
1 回答junit錯誤
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-11-29
最主要的報錯信息呢。。給我的給你參考
public void test1(){
?? ??? ?Configuration configuration = new Configuration().configure();
?? ??? ?//創建配置對象
?? ??? ?
?? ??? ?ServiceRegistry st = new ServiceRegistryBuilder().
?? ??? ??? ??? ?applySettings(configuration.getProperties()).buildServiceRegistry();
?? ??? ?//創建服務注冊對象
?? ??? ?
?? ??? ?SessionFactory sf = configuration.buildSessionFactory(st);
?? ??? ?//創建會話工廠對象
?? ??? ?
?? ??? ?Session session = sf.openSession();
?? ??? ?//打開會話
?? ??? ?
?? ??? ?Transaction tx = session.beginTransaction();
?? ??? ?//打開事務
?? ??? ?
?? ??? ?Book book = new Book();
?? ??? ?//生成學生對象
?? ??? ?
?? ??? ?session.save(book);
?? ??? ?//保存對象進入數據庫
?? ??? ?
?? ??? ?tx.commit();
?? ??? ?//提交事務
?? ??? ?
?? ??? ?session.close();
?? ??? ?//關閉會話
?? ??? ?
?? ??? ?sf.close();
?? ??? ?//關閉會話工廠
?? ?}
2016-11-29
謝謝拉、、下次提問最好給出錯誤信息。。很多像我們這樣剛剛學的都是配置文件出錯的。。