全民快乐8

你当前所在位置:全民快乐8 > IT就业问题 > Java面试题及答案(12/19)——Hibernate

Java面试题及答案(12/19)——Hibernate

113. 为什么要使用 hibernate?

 

● DUIJDBCFANGWENSHUJUKUDEDAIMAZUOLEFENGZHUANG,DADAJIANHUALESHUJUFANGWENCENGFANSUODEZHONGFUXINGDAIMA。

● HibernateSHIYIGEJIYUJDBCDEZHULIUCHIJIUHUAKUANGJIA,SHIYIGEYOUXIUDEORMSHIXIAN。TAHENDACHENGDUDEJIANHUADAOCENGDEBIANMAGONGZUO

● hibernateSHIYONGJavaFANSHEJIZHI,ERBUSHIZIJIEMAZENGQIANGCHENGXULAISHIXIANTOUMINGXING。

● hibernateDEXINGNENGFEICHANGHAO,YINWEITASHIGEQINGLIANGJIKUANGJIA。YINGSHEDELINGHUOXINGHENCHUSE。TAZHICHIGEZHONGGUANXISHUJUKU,CONGYIDUIYIDAODUODUIDUODEGEZHONGFUZAGUANXI。

 

114. 什么是 ORM 框架?

 

DUIXIANG-GUANXIYINGSHE(Object-Relational Mapping,JIANCHENGORM),MIANXIANGDUIXIANGDEKAIFAFANGFASHIDANGJINQIYEJIYINGYONGKAIFAHUANJINGZHONGDEZHULIUKAIFAFANGFA,GUANXISHUJUKUSHIQIYEJIYINGYONGHUANJINGZHONGYONGJIUCUNFANGSHUJUDEZHULIUSHUJUCUNCHUXITONG。DUIXIANGHEGUANXISHUJUSHIYEWUSHITIDELIANGZHONGBIAOXIANXINGSHI,YEWUSHITIZAINEICUNZHONGBIAOXIANWEIDUIXIANG,ZAISHUJUKUZHONGBIAOXIANWEIGUANXISHUJU。NEICUNZHONGDEDUIXIANGZHIJIANCUNZAIGUANLIANHEJICHENGGUANXI,ERZAISHUJUKUZHONG,GUANXISHUJUWUFAZHIJIEBIAODADUODUIDUOGUANLIANHEJICHENGGUANXI。YINCI,DUIXIANG-GUANXIYINGSHE(ORM)XITONGYIBANYIZHONGJIANJIANDEXINGSHICUNZAI,ZHUYAOSHIXIANCHENGXUDUIXIANGDAOGUANXISHUJUKUSHUJUDEYINGSHE.

 

115. hibernate 中如何在控制台查看打印的 sql 语句?

 

ZAI Config LIMIANBA hibernate. show_SQL SHEZHIWEI true JIUKEYI。DANBUJIANYIKAIQI,KAIQIZHIHOUHUIJIANGDICHENGXUDEYUNXINGXIAOLV。

 

116. hibernate 有几种查询方式?

 

全民快乐8● hqlCHAXUN

● sqlCHAXUN

● TIAOJIANCHAXUN

 

Java面试题-Hibernate

 

117. hibernate 实体类可以被定义为 final 吗?

 

全民快乐8KEYIJIANGHibernateDESHITILEIDINGYIWEIfinalLEI,DANZHEIZHONGZUOFABINGBUHAO。YINWEIHibernateHUISHIYONGDAILIMOSHIZAIYANCHIGUANLIANDEQINGKUANGXIATIGAOXINGNENG,RUGUONIBASHITILEIDINGYICHENGfinalLEIZHIHOU,YINWEI JavaBUYUNXUDUIfinalLEIJINXINGKUOZHAN,SUOYIHibernateJIUWUFAZAISHIYONGDAILILE,RUCIYILAIJIUXIANZHILESHIYONGKEYITISHENGXINGNENGDESHOUDUAN。BUGUO,RUGUONIDECHIJIUHUALEISHIXIANLEYIGEJIEKOUERQIEZAIGAIJIEKOUZHONGSHENGMINGLESUOYOUDINGYIYUSHITILEIZHONGDESUOYOUpublicDEFANGFALUNDAOHUA,NIJIUNENGGOUBIMIANCHUXIANQIANMIANSUOSHUODEBULIHOUGUO。

 

118. 在 hibernate 中使用 Integer 和 int 做映射有什么区别?

 

全民快乐8ZAIHibernateZHONG,RUGUOJIANGOIDDINGYIWEIIntegerLEIXING,NEIMEHibernateJIUKEYIGENJUQIZHISHIFOUWEInullERPANDUANYIGEDUIXIANGSHIFOUSHILINSHIDE,RUGUOJIANGOIDDINGYIWEILEintLEIXING,HAIXUYAOZAIhbmYINGSHEWENJIANZHONGSHEZHIQIunsaved-valueSHUXINGWEI0。

 

119. hibernate 是如何工作的?

 

hibernateGONGZUOYUANLI:

 

Java面试题-Hibernate

 

120. get()和 load()的区别?

 

● load() MEIYOUSHIYONGDUIXIANGDEQITASHUXINGDESHIHOU,MEIYOUSQL YANCHIJIAZAI

● get() MEIYOUSHIYONGDUIXIANGDEQITASHUXINGDESHIHOU,YESHENGCHENGLESQL LIJIJIAZAI

 

121. 说一下 hibernate 的缓存机制?

 

全民快乐8HibernateZHONGDEHUANCUNFENWEIYIJIHUANCUNHEERJIHUANCUN。

 

YIJIHUANCUNJIUSHI Session JIBIEDEHUANCUN,ZAISHIWUFANWEINEIYOUXIAOSHI,NEIZHIDEBUNENGBEIXIEZAI。ERJIHUANCUNSHI SesionFactoryJIBIEDEHUANCUN,CONGYINGYONGQIDONGDAOYINGYONGJIESHUYOUXIAO。SHIKEXUANDE,MORENMEIYOUERJIHUANCUN,XUYAOSHOUDONGKAIQI。BAOCUNSHUJUKUHOU,HUANCUNZAINEICUNZHONGBAOCUNYIFEN,RUGUOGENGXINLESHUJUKUJIUYAOTONGBUGENGXIN。

 

全民快乐8SHENMEYANGDESHUJUSHIHECUNFANGDAODIERJIHUANCUNZHONG?

 

Java面试题-Hibernate

 

KUOZHAN:hibernateDEERJIHUANCUNMORENSHIBUZHICHIFENBUSHIHUANCUNDE。SHIYONG memcahe,redisDENGZHONGYANGHUANCUNLAIDAITIERJIHUANCUN。

 

122. hibernate 对象有哪些状态?

 

hibernateLIDUIXIANGYOUSANZHONGZHUANGTAI:

 

● Transient(SHUNSHI):DUIXIANGGANGnewCHULAI,HAIMEISHEid,SHELEQITAZHI。

● Persistent(CHIJIU):DIAOYONGLEsave()、saveOrUpdate(),JIUBIANCHENGPersistent,YOUid。

全民快乐8● etached(TUOGUAN):DANGsession close()WANZHIHOU,BIANCHENGDetached。

 

Java面试题-Hibernate

 

123. 在 hibernate 中 getCurrentSession 和 openSession 的区别是什么?

 

openSession CONGZIMIANSHANGKEYIKANDECHULAI,SHIDAKAIYIGEXINDEsessionDUIXIANG,ERQIEMEICISHIYONGDOUSHIDAKAIYIGEXINDEsession,JIARULIANXUSHIYONGDUOCI,ZEHUODEDEsessionBUSHITONGYIGEDUIXIANG,BINGQIESHIYONGWANXUYAODIAOYONGcloseFANGFAGUANBIsession。

 

getCurrentSession ,CONGZIMIANSHANGKEYIKANDECHULAI,SHIHUOQUDANGQIANSHANGXIAWENYIGEsessionDUIXIANG,DANGDIYICISHIYONGCIFANGFASHI,HUIZIDONGCHANSHENGYIGEsessionDUIXIANG,BINGQIELIANXUSHIYONGDUOCISHI,DEDAODEsessionDOUSHITONGYIGEDUIXIANG,ZHEIJIUSHIYUopenSessionDEQUBIEZHIYI,JIANDANERYAN,getCurrentSession JIUSHI:RUGUOYOUYIJINGSHIYONGDE,YONGJIUDE,RUGUOMEIYOU,JIANXINDE。

 

ZHUYI:ZAISHIJIKAIFAZHONG,WANGWANGSHIYONGgetCurrentSessionDUO,YINWEIYIBANSHICHULITONGYIGESHIWU(JISHISHIYONGYIGESHUJUKUDEQINGKUANG),SUOYIZAIYIBANQINGKUANGXIABIJIAOSHAOSHIYONGopenSessionHUOZHESHUOopenSessionSHIBIJIAOLAOJIUDEYITAOJIEKOULE。

 

124. hibernate 实体类必须要有无参构造函数吗?为什么?

 

BIXU,YINWEIhibernateKUANGJIAHUIDIAOYONGZHEIGEMORENGOUZAOFANGFALAIGOUZAOSHILIDUIXIANG,JIClassLEIDEnewInstanceFANGFA,ZHEIGEFANGFAJIUSHITONGGUODIAOYONGMORENGOUZAOFANGFALAICHUANGJIANSHILIDUIXIANGDE。

 

全民快乐8LINGWAIZAITIXINGYIDIAN,RUGUONIMEIYOUTIGONGRENHEGOUZAOFANGFA,XUNIJIHUIZIDONGTIGONGMORENGOUZAOFANGFA(WUCANGOUZAOQI),DANSHIRUGUONITIGONGLEQITAYOUCANSHUDEGOUZAOFANGFADEHUA,XUNIJIJIUBUZAIWEINITIGONGMORENGOUZAOFANGFA,ZHEISHIBIXUSHOUDONGBAWUCANGOUZAOQIXIEZAIDAIMALI,FOUZEnew Xxxx()SHIHUIBAOCUODE,SUOYIMORENDEGOUZAOFANGFABUSHIBIXUDE,ZHIZAIYOUDUOGEGOUZAOFANGFASHICAISHIBIXUDE,ZHEILI“BIXU”ZHIDESHI“BIXUSHOUDONGXIECHULAI”。


课程预约

全民快乐8

全民快乐8

全民快乐8

全民快乐8

全民快乐8