1.hibernate åeclipselinkçåºå«
2.hibernateåibatisçåºå«
hibernate åeclipselinkçåºå«
Hibernate
Hibernate æ¯ä¸ä¸ªå¼æ¾æºä»£ç ç对象/å ³ç³»æ å°æ¡æ¶åæ¥è¯¢æå¡ãå®å¯¹ JDBC è¿è¡äºè½»é级ç对象å°è£ ï¼è´è´£ä» Java ç±»æ å°å°æ°æ®åºè¡¨ï¼å¹¶ä» Java æ°æ®ç±»åæ å°å° SQL æ°æ®ç±»åãå¨ 4.0 çæ¬ Hibenate å¼å§æ¯æå¤ç§æ·æ¶æââ对ä¸åç§æ·ä½¿ç¨ç¬ç«æ°æ®åºæç¬ç« Sechmaï¼å¹¶è®¡åå¨ 5.0 ä¸æ¯æå ±äº«æ°æ®è¡¨æ¨¡å¼ã
å¨ Hibernate 4.0 ä¸çå¤ç§æ·æ¨¡å¼æä¸ç§ï¼éè¿ hibernate.multiTenancy å±æ§æä¸é¢å ç§é ç½®ï¼
NONEï¼éå¤ç§æ·ï¼ä¸ºé»è®¤å¼ã
SCHEMAï¼ä¸ä¸ªç§æ·ä¸ä¸ª Schemaã
DATABASEï¼ä¸ä¸ªç§æ·ä¸ä¸ª databaseã
DISCRIMINATORï¼ç§æ·å ±äº«æ°æ®è¡¨ã计åå¨ Hibernate5 ä¸å®ç°
EclipseLink
EclipseLink æ¯ Eclipse åºéä¼ç®¡çä¸çå¼æºæä¹ å±æå¡é¡¹ç®ï¼ä¸º Java å¼å人åä¸åç§æ°æ®æå¡ï¼æ¯å¦ï¼æ°æ®åºãweb servicesã对象XMLæ å°ï¼OXMï¼ãä¼ä¸ä¿¡æ¯ç³»ç»ï¼EISï¼çï¼äº¤äºæä¾äºä¸ä¸ªå¯æ©å±æ¡æ¶ï¼ç®åæ¯æçæä¹ å±æ åä¸å æ¬ï¼
Java Persistence API (JPA)
Java Architecture for XML Binding (JAXB)
Java Connector Architecture (JCA)
Service Data Objects (SDO)
EclipseLink åèº«æ¯ Oracle TopLink,菜鸟商城 完整源码 å¹´ Oracle å°åè ç»å¤§é¨åæç®ç»äº Eclipse åºéä¼ï¼æ¬¡å¹´ EclipseLink 被 Sun æéæ为 JPA 2.0 çåèå®ç°ã
注: ç®å EclipseLink2.5 å®å ¨æ¯æ å¹´åå¸ç JPA2.1(JSR ï¼ ã
å¨å®æ´å®ç° JPA æ åä¹å¤ï¼é对 SaaS ç¯å¢ï¼å¨å¤ç§æ·çé离æ¹é¢ EclipseLink æä¾äºå¾å¥½çæ¯æ以åçµæ´»å°è§£å³æ¹æ¡ã
åºç¨ç¨åºé离
é离ç容å¨/åºç¨æå¡å¨
å ±äº«å®¹å¨/åºç¨æå¡å¨çåºç¨ç¨åºé离
åä¸åºç¨ç¨åºå çå ±äº«ç¼åä½é离ç entity manager factory
å ±äº«ç entity manager factory ä½æ¯é离ç entity manager
æ°æ®é离
é离çæ°æ®åº
é离çSchema/表空é´
é离ç表
å ±äº«è¡¨ä½é离çè¡
æ¥è¯¢è¿æ»¤
Oracle Virtual Private Database (VPDï¼
对äºå¤ç§æ·æ°æ®æºé离主è¦æ以ä¸æ¹æ¡
Single-Table Multi-tenancyï¼ä¾é ç§æ·åºååï¼tenant discriminator columnsï¼æ¥é离表çè¡ï¼å®ç°å¤ç§æ·å ±äº«è¡¨ã
Table-Per-Tenant Multi-tenancyï¼ä¾é 表çç§æ·åºå(table tenant discriminator)æ¥é离表ï¼å®ç°ä¸ç§æ·ä¸ä¸ªè¡¨ï¼å¤§ä½ç±»ä¼¼äºä¸æçå ±äº«æ°æ®åºç¬ç«Schema模å¼ã
Virtual Private Databaseï¼VPD ) Multi-tenancyï¼ä¾é Oracle VPD èªèº«çå®å ¨è®¿é®çç¥ï¼åºäºå¨æSQL whereåå¥ç¹æ§ï¼ï¼å®ç°å¤ç§æ·å ±äº«è¡¨ã
æ¨èé 读è¿ç¯æç« ï¼/java/j-lo-dataMultitenant/ï¼è®²çä¸éã
hibernateåibatisçåºå«
æ¨è解çï¼1ï¼
Hibernate ããHibernateæ¯ä¸ä¸ªå¼æ¾æºä»£ç çå¯¹è±¡å ³ç³»æ å°æ¡æ¶ï¼å®å¯¹JDBCè¿è¡äºé常轻é级ç对象å°è£ ï¼ä½¿å¾Javaç¨åºåå¯ä»¥éå¿æ欲ç使ç¨å¯¹è±¡ç¼ç¨æç»´æ¥æ纵æ°æ®åºã Hibernateå¯ä»¥åºç¨å¨ä»»ä½ä½¿ç¨JDBCçåºåï¼æ¢å¯ä»¥å¨Javaç客æ·ç«¯ç¨åºå®ç¨ï¼ä¹å¯ä»¥å¨Servlet/JSPçWebåºç¨ä¸ä½¿ç¨ï¼æå ·é©å½æä¹çæ¯ï¼Hibernateå¯ä»¥å¨åºç¨EJBçJ2EEæ¶æä¸å代CMPï¼å®ææ°æ®æä¹ åçéä»»ãEclipseå¹³å°ä¸çHibernateè¾ å©å¼åå·¥å ·:ãHibernate SynchronizerããMiddlegenIDEã ããIBATIS ãã使ç¨ibatis æä¾çORMæºå¶ï¼å¯¹ä¸å¡é»è¾å®ç°äººåèè¨ï¼é¢å¯¹çæ¯çº¯ç²¹çJavaå¯¹è±¡ï¼ è¿ä¸å±ä¸éè¿Hibernate å®ç°ORM èè¨åºæ¬ä¸è´ï¼è对äºå ·ä½çæ°æ®æä½ï¼Hibernate ä¼èªå¨çæSQL è¯å¥ï¼èibatis åè¦æ±å¼åè ç¼åå ·ä½çSQL è¯å¥ãç¸å¯¹Hibernateç âå ¨èªå¨âORMæºå¶èè¨ï¼ibatis 以SQLå¼åçå·¥ä½éåæ°æ®åºç§»æ¤æ§ä¸ç让æ¥ï¼ä¸ºç³»ç» 设计æä¾äºæ´å¤§çèªç±ç©ºé´ãä½ä¸ºâå ¨èªå¨âORM å®ç°çä¸ç§æçè¡¥å ï¼ibatis çåºç°æ¾ å¾å«å ·æä¹ã
[æ°æ®æå¿« 大æ°æ®å®éªå®¤æä¾ ][datacaptor from aosustudio]
æ¨è解çï¼2ï¼
ä¸.å ±åç¹ï¼
1.é½æ¯O/R mappingæ¡æ¶ï¼ç´æ¥ä¸æ°æ®åºæ交éã
2.é½æä¾æ¹è¨æ¯æä¸åç±»åæ°æ®åºç访é®ï¼éè¿xmlæä»¶æ ¼å¼å°æ°æ®åºè¡¨ä¸java对象è¿æ¥èµ·æ¥ã
3.é½å¯ä»¥äº¤ç»springæ¥ç®¡ç
4.é½æ¯å¼æºè½¯ä»¶
äº.åºå«ï¼
hibernateæ¯å½åæµè¡çO/Ræ¡æ¶ï¼æ¥èªäºsf.netï¼ç°å¨å·²æ为HBOSSçä¸é¨åã hibernateç¸å¯¹è¾å¤æï¼å¦ä¹ å¨æé¿ã
ibatis/mybatis æ¯å¦å¤ä¸ç§ä¼ç§ço/r mappingæ¡æ¶ï¼ç®åå±äºapacheçä¸ä¸ªå项ç®äºãibatisä¸æå¿«ï¼å¾å®¹æå¦å¦ä¹ ã
ä¸åçï¼
hibernate对æ°æ®ç»æè¿è¡äºå¾å¥½çå°è£ ï¼å¯ä»¥å®ç°java对象ä¹å°±æ¯POJOæ¯æ°æ®åºè¡¨ä¹é´çæ å°ï¼è¿è½æ ¹æ®POJOåSQLèªå¨çæ表åæ§è¡å½ä»¤ãç¨åºåå¾å¾åªéå®ä¹å¥½äºpojo å°æ°æ®åºè¡¨çæ å°å ³ç³»ï¼å³å¯éè¿hibernate æä¾çæ¹æ³å®ææä¹ å±æä½ãç¨åºåçè³ä¸éè¦å¯¹sql ççç»ææ¡ï¼ hibernate/ojb ä¼æ ¹æ®å¶å®çåå¨é»è¾ï¼èªå¨çæ对åºçsql 并è°ç¨jdbc æ¥å£å 以æ§è¡ã
èibatis åéç¹å¨äºpojo ä¸sqlä¹é´çæ å°å ³ç³»ãibatisä¸è½è®©æ们éè¿POJOçæSQLè¯å¥æ¥æ§è¡ ãå ·ä½çsql éè¦ç¨åºåç¼åï¼ç¶åéè¿æ å°é ç½®æ件ï¼å°sqlæéçåæ°ï¼ä»¥åè¿åçç»æå段æ å°å°æå®pojoã
å.æºå¶
使ç¨ibatis æä¾çormæºå¶ï¼å¯¹ä¸å¡é»è¾å®ç°äººåèè¨ï¼é¢å¯¹çæ¯çº¯ç²¹çjava对象ãè¿ä¸å±ä¸éè¿hibernate å®ç°orm èè¨åºæ¬ä¸è´ï¼è对äºå ·ä½çæ°æ®æä½ï¼hibernateä¼èªå¨çæsql è¯å¥ï¼èibatis åè¦æ±å¼åè ç¼åå ·ä½çsql è¯å¥ãç¸å¯¹hibernateèè¨ï¼ibatis 以sqlå¼åçå·¥ä½éåæ°æ®åºç§»æ¤æ§ä¸ç让æ¥ï¼ä¸ºç³»ç»è®¾è®¡æä¾äºæ´å¤§çèªç±ç©ºé´ã
äº.ç³»ç»ç»´æ¤æè äºæ¬¡å¼å
å½ç³»ç»ç»´æ¤æè äºæ¬¡å¼å,æ æ³å¯¹æ°æ®åºç»æåå°æ§å¶åä¿®æ¹,é£ibatisççµæ´»æ§å°æ¯hibernateæ´éå
å .æµ·éæ°æ®
ç³»ç»æ°æ®å¤çé巨大ï¼æ§è½è¦æ±æ为èå»ï¼è¿å¾å¾æå³çæä»¬å¿ é¡»éè¿ç»è¿é«åº¦ä¼åçsqlè¯å¥ï¼æåå¨è¿ç¨ï¼æè½è¾¾å°ç³»ç»æ§è½è®¾è®¡ææ ãå¨è¿ç§æ åµä¸ibatisä¼ææ´å¥½çå¯æ§æ§å表ç°ã
ä¸.èªå¨åç¨åº¦
ibatiséè¦æåsqlè¯å¥ï¼ä¹å¯ä»¥çæä¸é¨åï¼hibernateååºæ¬ä¸å¯ä»¥èªå¨çæï¼å¶å°ä¼åä¸äºhqlãåæ ·çéæ±,ibatisçå·¥ä½éæ¯ hibernateè¦å¤§å¾å¤ã类似çï¼å¦ææ¶åå°æ°æ®åºå段çä¿®æ¹ï¼hibernateä¿®æ¹çå°æ¹å¾å°ï¼èibatisè¦æé£äºsql mappingçå°æ¹ä¸ä¸ä¿®æ¹ã
å «.ä¸æ°æ®æ å°å ³ç³»
ibatis以æ°æ®åºå段ä¸ä¸å¯¹åºæ å°å¾å°çpoåhibernteè¿ç§å¯¹è±¡åæ å°å¾å°çpoæ¯æªç¶ä¸åçï¼æ¬è´¨åºå«å¨äºè¿ç§poæ¯æå¹³åçï¼ä¸åhibernateæ å°çpoæ¯å¯ä»¥è¡¨è¾¾ç«ä½ç对象继æ¿ï¼èåççå ³ç³»çï¼è¿å°ä¼ç´æ¥å½±åå°ä½ çæ´ä¸ªè½¯ä»¶ç³»ç»ç设计æè·¯ã
ä¹.ææ¯æ¯æ
hibernateç°å¨å·²ç»æ¯ä¸»æµo/r mappingæ¡æ¶ï¼ä»ææ¡£ç丰å¯æ§ï¼äº§åçå®åæ§ï¼çæ¬çå¼åé度é½è¦å¼ºäºibatis
å.å®ç°è¿ç¨æ¥ç
1.hibernateé ç½®,è¿è¡æ°æ®åºè¿æ¥ã
2.POJOä¸æ°æ®åºæ å°çxmlæ件ä»ç»
3..å¾å°sessionFactoryæ们就å¯ä»¥éè¿ä¼è¯å·¥åæä½æ°æ®åº
4ãibatisé 置信æ¯è®¾ç½®
5.POJOä¸æ°æ®åºç建ç«xmlæ件å®ä¹
6.å è½½ibatisé ç½®æ件ï¼ç»clientåå§å
6.éè¿clientæä½æ°æ®åº
亲ï¼è®°å¾é纳ä¸ä¸å¦
[æ°æ®æå¿« 大æ°æ®å®éªå®¤æä¾ ][datacaptor from aosustudio]
æ¨è解çï¼3ï¼
é½æ¯javaçä¸ç§æ¡æ¶ï¼hibernateé çæ¯hqlè¯è¨ï¼é¢åçæ¯object,ibatisé çæ¯sqlè¯è¨ï¼æ´æ¥è¿æ°æ®åºï¼é ç½®æ¯hibernateçµæ´»ï¼ä¹æ¯hibernateæçé«