éå¬æ¡å
ãã¼ã¸ã¯æ¬¡ã§ãã
【東京】JJUG ナイトセミナー 「Java O/Rマッパー特集」 7/26(水)開催 - 日本Javaユーザーグループ/Japan Java User Group | Doorkeeper
togetterã¾ã¨ã
【東京】JJUG ナイトセミナー 「Java O/Rマッパー特集」 7/26(水)開催 #jjug - Togetter
30åãã¤ã§4ã¤ã®O/Rãããã¼ã©ã¤ãã©ãªã®è©±ãèãã¾ããã
25åã§ãããJPAï¼å¤ç°çæããï¼
ã¹ã©ã¤ãè³æï¼https://speakerdeck.com/masatoshitada/jpa-in-25min
JPAã¯ãJSR338ã§çå®ãããä»æ§ã§ããä»æ§æ¸ã¯PDFã§600ãã¼ã¸ã«åã¶éã§ããã¢ããã¼ã·ã§ã³ã¨APIã®è¦å®ã§ãJPAã使ç¨ããã«ã¯ãJSR338ãå®è£ ããããããã®ã©ã¤ãã©ãªãå¿ è¦ã§ããä¾ãã°ãHibernateãEclipseLinkãããã¾ããæ¬æ¥ã®ã»ãã·ã§ã³ã¯Hibernateãç¨ãã¦ãã¾ããæ¯ãèãã«ã¯å®è£ åºæã®å·®ç°ãããããã§ãã
JPAã¯ãã¨ã³ãã£ãã£ã¨ãã¼ãã«ã¨ã1対1ã§ä½ããã®ã§ãããªã¬ã¼ã·ã§ã³ã®1:å¤ãªã©*1ã«å¯¾å¿ãã¦ãã¾ãã
- Tipsï¼SQLãã°ã®åºåãå¿ ãè¨å®ããã
ç¶æ 管çãéè¦ãæ°¸ç¶åã³ã³ããã¹ããè¶ éè¦ããã®ã»ãã·ã§ã³ã§ä¸çªå¤§äºãªã®ã¯ã¨ã³ãã£ãã£ã®ç¶æ é·ç§»ã§ãã
ã¨ã³ãã£ãã£ã®ä½æã«ã¯ã主ãã¼ã»ã¼å¿
é ã§ãã
ã¨ã³ãã£ãã£ã¯ãCRUDæä½ã®çªå£ã§ã¯ããã¾ããã
å
¨ãã£ã¼ã«ããINSERT対象ã¨ãªããåé¿ãã@Transientã¢ããã¼ã·ã§ã³ããã
merge()ã¯ãSELECT + UPDATEãçºè¡ããã¾ãã
- è½ã¨ãç©´ï¼merge ã¯å¼æ°ã«æå®ããã¨ã³ãã£ãã£ã®ã³ãã¼ãä½ããæ»ãå¤ã¨ãã¦è¿ãããããMANAGEDã¨ãªããå¼æ°ã«æå®ããã¨ã³ãã£ãã£ã¯MANAGEDã«ãªããªãã
JPQLã¯ãINSERTç¸å½ã¯ãªããSELECT/UPDATE/DELETEç¸å½ãçºè¡ãããSQLã¯å®è£ ä¾åãå¯åãåããã¯WHEREå¥ã¨HAVINGå¥ãã§ããªããã¨ã¯ãINSERTãéåæ¼ç®ãFROMå¥ã§ã®å¯åãåããã
ãã§ããã«ã¯EAGER/LAZYãããEAGERã¯ãHibernateã§ã¯JOINãEclipseLinkã§ã¯SELECTã使ããã¾ãã
- 注æç¹ï¼LAZYãã§ããã§ãã©ã³ã¶ã¯ã·ã§ã³çµäºå¾ã«ãã§ããããã¨ä¾å¤ãçºçï¼å®è£ ç³»ã§æ¯ãèãç°ãªãï¼
- åºæ¬ã¯LAZYã使ãã
- JOIN FETCH + DISTINCTã§ãã¼ã¿éè¤ãé²ã
Spring Data JPAã¯ã¨ã¦ã便å©ã§ããååã¯ããã§ãããSpringã§ãªãã¦ã使ãã¾ãã
JPAã使ãã«ã¯ãæ£ããç¥èã¨é©ããç¶æ³ãå¿ è¦ã§ãã次ã®3æ¡ä»¶ããã¹ã¦æºè¶³ãã¦ããªãã¨JPAã®ä½¿ç¨ã§ãããã¾ãã
MyBatis ãå©ç¨ãã Web Application éçºã«ã¤ãã¦ã®ãç´¹ä»ï¼Tokuhiro Matsunoããï¼
ã¹ã©ã¤ãè³æï¼https://www.slideshare.net/tokuhirom/mybatis-web-application
å
ã»ã©ã®JPAã¨ã¯å¯¾æ¥µã«ããæãã®ã©ã¤ãã©ãªã§ãã
SQLã¯ç´æ¥ï¼æã§ï¼è¨è¿°ãããããinterfaceãéãã¦å¼ã³åºããçµæãBeanã«æ ¼ç´ããã¾ããjava.lang.reflect.Proxyã使ã£ã¦å®è£
ããã¦ãã¾ãã
主ãã¼ããªãã¦ãOKã§ãMyBatisåæã§ã¯ä½ããã¦ããªãDBã§ãOKããµãã¯ã¨ãªãOKãN+1åé¡ã¯ãªãã§ãã
ç´æ¥SQLæ¸ãã®ã§ãDBä¾åã«ãªãã¾ãï¼DBä¾åãã¦åé¡ã®ãªãããã¸ã§ã¯ããå¤ãã¯ãï¼ã
SQLã®æ¸ãæ¹ã¯ã1) XMLã2)ã¢ããã¼ã·ã§ã³ã3)Javaã®DSL ã¨ããã¾ããLINE社å
ã§ã¯ã1)ã7å²ã2)ã3å²ãæè¿2ï¼ãå¢ãã¤ã¤ããã¨ã®ãã¨ã§ãã
IntelliJã§ã¯ã¢ããã¼ã·ã§ã³ã®SQLããã¾ãèªèãããããã®ã§è¨è¿°ã«ä¾¿å©ãªã©ã
ãã£ãããããDomaï¼ãããã¿ããï¼
ã¹ã©ã¤ãè³æï¼http://backpaper0.github.io/ghosts/doma-zakkuri/#1
ã¢ããã¼ã·ã§ã³ããã»ãã·ã³ã°ã使ã£ãã©ã¤ãã©ãªã§ãã
O/Rãããã¼ã¨ããããResultSetãããã¼ã§ãã
Java SE 8対å¿ã§ãdate and time APIãOptionalãStream APIã«ã対å¿ãã¦ãã¾ãã
SQLã¯æã§æ¸ããã¯ã©ã¹ãã¹ä¸ã«SQLãã¡ã¤ã«ã¨ãã¦ç½®ãã¾ãã2way SQLã¨å¼ã³ãDomaæ©è½ãSQLã®ã³ã¡ã³ãã§æ¸ãã¾ãããªã®ã§SQLã¨ãã¦ç´æ¥å®è¡ãå¯è½ã¨ãªãã¾ãã
ãã¡ã¤ã³ã¯ã©ã¹ã¨å¼ã¶å¤ãªãã¸ã§ã¯ãã«ã«ã©ã ããããã³ã°ã§ãã¾ãï¼ãªãã¸ã§ã¯ãæåï¼DDDï¼ã®ãã¡ã¤ã³ã¨ã¯å¥ç©ï¼ã
ã³ã³ãã¤ã«æã«ããããæ¤è¨¼ãã¦ããã¾ããã¨ã³ãã£ãã£ã¯ã¤ãã¥ã¼ã¿ãã«ã«ã§ãã¾ã¾ãã
ã§ããªããã¨ã¯ãSELECTã¯ã¨ãªã®èªåçæã親åãªã©ã®æ§é ã®ã¨ã³ãã£ãã£ã¸ã®ãããã³ã°ã
Reladomoå ¥éï¼ä¼è¤åå¿ããï¼
ã¹ã©ã¤ãè³æï¼https://www.slideshare.net/itohiro73/reladomo-jjug-jjug
ã´ã¼ã«ããã³ãµãã¯ã¹ã§2004å¹´é ããã¨ã³ã¿ã¼ãã©ã¤ãºã«ä½¿ç¨ã2016å¹´ã«ãªã¼ãã³ã½ã¼ã¹åï¼APL 2.0ï¼ã
ãããã³ã°ãXMLã§å®ç¾©ããJavaã³ã¼ããçæï¼Abstractã¯ã©ã¹ï¼ããã¸ãã¹ãã¸ãã¯ã¯ç¶æ¿ãããµãã¯ã©ã¹ã«è¨è¿°ãã使ãæ¹ã§ãã
ãã£ãã·ã¥æ©æ§ãå
å®ãã¦ãã¾ãã
ãã¤ãã³ãã©ã«ã¢ãã«ã¨ããæéã2ã¤ã®è¦³ç¹ã§æ±ããããã«ãªã£ã¦ããã®ãã¾ãåªããã®ã§ãã
GS Collectionããã¤ãã£ããµãã¼ããã¦ããã®ã§ãã¼ã¿ãã¼ã¹ãããã¼ã¿ãGS Collectionã«æ¾ãè¾¼ãã§ã¤ã³ã¡ã¢ãªã§é«åº¦ãªãã¼ã¿å¦çãã§ããããã«ãªã£ã¦ããã®ãããããã§ããGS Collectionã¯ãEclipse Collectionã«å¯è´ï¼ï¼ï¼ããã¦ãã¾ããããã¡ãã¸ã®å¯¾å¿ã¯ç¾å¨é²è¡ä¸ã¨ã®ãã¨ã§ãã
Javaã®ã³ã¼ãã§è¨è¿°ã§ããããªãã¸ã§ã¯ãæåã®æ¥µã¿ã®ãããªO/Rãããã¼ã§ãã
ææ³
JPAã®ä½¿ç¨ãé©ãã3ã¤ã®æ¡ä»¶ã§ããã¼ã¿ãã¼ã¹ã«æãå
¥ããããï¼æ°è¦ã«è¨è¨ã§ããï¼ãæãããã¦ãã¾ãããæ¢åã®ãªã¬ã¼ã·ã§ãã«ãã¼ã¿ãã¼ã¹ã使ã£ãã¢ããªã±ã¼ã·ã§ã³ãéçºããéã«ãJPAã§ã¯è¾ã¿ãåºãã®ã§ãããã
Hibernateã¨EclipseLinkã¨ã§æ¯ãèãã«éããããã®ã¯ä»ååãã¦ç¥ãã¾ããã
ä»åã®ãã¤ãã»ããã¼ã§ãJPAã®ä½¿ãã©ãããèããã®ãåç©«ã§ãã
JPAããO/Rãããã¼ã ã¨ããã¨ã次ã®MyBatisã¯ããããSQLã使ããã¼ã¿ãã¼ã¹ã¢ã¯ã»ã¹ã©ã¤ãã©ãªã§ãããJPAãSQLãé è½ãã¦ããã®ã¨éã£ã¦ãSQLãç©æ¥µçã«ä½¿ã£ã¦ããã©ã¤ãã©ãªã§ãã
Domaã¯ã¡ãã£ã¨ä½¿ãã©ãããé£ããããSQLã使ããã¼ã¿ãã¼ã¹ã¢ã¯ã»ã¹ã©ã¤ãã©ãªã§ããããã¡ã¤ã³ã¯ã©ã¹ã¨ããåã®å¤ãªãã¸ã§ã¯ãã¨ãã¦ãã¼ã¿ã¯ã©ã¹çãªãã®ã¨ãã¼ã¿ãã¼ã¹ããããã³ã°ãã¦ããã¾ããã§ããå¤ãªãã¸ã§ã¯ããªã®ã§ã»ã»ã»ã
Reladomoã¯ããã¼ã¿ãã¼ã¹ã¸ã®ã¢ã¯ã»ã¹ãJavaã³ã¼ãããJavaã®APIãã©ãã©ãå¼ã¶ããã«æ¸ãããã¨ã¨ããã¤ãã³ãã©ã«ã¨ããç¹è²ãããã§ããã
ã¨ãããã¨ã§ãSQLã使ã£ã¦RDBMSãå¼·ãæèããã©ã¤ãã©ãªï¼MyBatisã¨Domaï¼ãSQLãé è½ãã¦RDBMSãæèããªãããã«ããã©ã¤ãã©ãªï¼JPAå®è£ ã©ã¤ãã©ãªãReladomoï¼ã¨ããããç¹è²ã®ãããã¼ã¿ãã¼ã¹ã¢ã¯ã»ã¹ã©ã¤ãã©ãªã®ç´¹ä»ãèããã¨ãã§ããã®ãä»åã®ãã¤ãã»ããã¼ã®ããã£ãã¨ããã§ãã
*1:@OneToOne, @OneToMany, @ManyToOne, @ManyToMany