From d00308836475c4669916b4506c7251496cf4142f Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Tue, 22 Feb 2022 12:01:06 +0530 Subject: [PATCH] JAVA-10081 :Create new module hibernate-mapping from spring-hibernate-5 module --- .../hibernate-many-to-many/.gitignore | 13 ++ .../hibernate-many-to-many/README.md | 7 + .../_2.fdt | Bin 0 -> 160 bytes .../_2.fdx | Bin 0 -> 84 bytes .../_2.fnm | Bin 0 -> 532 bytes .../_2.nvd | Bin 0 -> 65 bytes .../_2.nvm | Bin 0 -> 88 bytes .../_2.si | Bin 0 -> 514 bytes .../_2.tvd | Bin 0 -> 392 bytes .../_2.tvx | Bin 0 -> 79 bytes .../_2_Lucene50_0.doc | Bin 0 -> 190 bytes .../_2_Lucene50_0.pos | Bin 0 -> 162 bytes .../_2_Lucene50_0.tim | Bin 0 -> 914 bytes .../_2_Lucene50_0.tip | Bin 0 -> 195 bytes .../_3.cfe | Bin 0 -> 341 bytes .../_3.cfs | Bin 0 -> 2119 bytes .../_3.si | Bin 0 -> 371 bytes .../segments_5 | Bin 0 -> 198 bytes .../write.lock | 0 .../hibernate-many-to-many/pom.xml | 136 ++++++++++++++ .../hibernate/manytomany/model/Employee.java | 176 +++++++++--------- .../hibernate/manytomany/model/Project.java | 122 ++++++------ .../manytomany/util/HibernateUtil.java | 90 ++++----- .../manytomany/spring/PersistenceConfig.java | 140 +++++++------- .../persistence/dao/common/AbstractDao.java | 14 ++ .../dao/common/AbstractHibernateDao.java | 59 ++++++ .../persistence/dao/common/IOperations.java | 20 ++ .../manytomany/dao/IEmployeeDao.java | 16 +- .../manytomany/dao/IProjectDao.java | 16 +- .../manytomany/dao/impl/EmployeeDao.java | 32 ++-- .../manytomany/dao/impl/ProjectDao.java | 34 ++-- .../baeldung/spring/PersistenceConfig.java | 75 ++++++++ .../src/main/resources/import.sql | 31 +++ .../src/main/resources/logback.xml | 19 ++ .../src/main/resources/manytomany.cfg.xml | 30 +-- .../main/resources/persistence-h2.properties | 21 +++ .../java/com/baeldung/SpringContextTest.java | 19 ++ ...notationJavaConfigMainIntegrationTest.java | 98 +++++----- ...nyToManyAnnotationMainIntegrationTest.java | 160 ++++++++-------- .../src/test/resources/.gitignore | 13 ++ .../hibernate/criteria/model/Item.hbm.xml | 22 +++ .../src/test/resources/import.sql | 21 +++ .../src/test/resources/manytomany.cfg.xml | 0 .../spring-hibernate-5/README.md | 1 - .../spring-hibernate-5/pom.xml | 20 ++ .../src/test/resources/import.sql | 1 + 46 files changed, 948 insertions(+), 458 deletions(-) create mode 100644 persistence-modules/hibernate-many-to-many/.gitignore create mode 100644 persistence-modules/hibernate-many-to-many/README.md create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.fdt create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.fdx create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.fnm create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.nvd create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.nvm create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.si create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.tvd create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.tvx create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2_Lucene50_0.doc create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2_Lucene50_0.pos create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2_Lucene50_0.tim create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2_Lucene50_0.tip create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_3.cfe create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_3.cfs create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_3.si create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/segments_5 create mode 100644 persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/write.lock create mode 100644 persistence-modules/hibernate-many-to-many/pom.xml rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/main/java/com/baeldung/hibernate/manytomany/model/Employee.java (96%) rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/main/java/com/baeldung/hibernate/manytomany/model/Project.java (95%) rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/main/java/com/baeldung/hibernate/manytomany/util/HibernateUtil.java (97%) rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/main/java/com/baeldung/manytomany/spring/PersistenceConfig.java (97%) create mode 100644 persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java create mode 100644 persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java create mode 100644 persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/IOperations.java rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/main/java/com/baeldung/persistence/manytomany/dao/IEmployeeDao.java (96%) rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/main/java/com/baeldung/persistence/manytomany/dao/IProjectDao.java (96%) rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/main/java/com/baeldung/persistence/manytomany/dao/impl/EmployeeDao.java (96%) rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/main/java/com/baeldung/persistence/manytomany/dao/impl/ProjectDao.java (96%) create mode 100644 persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/spring/PersistenceConfig.java create mode 100644 persistence-modules/hibernate-many-to-many/src/main/resources/import.sql create mode 100644 persistence-modules/hibernate-many-to-many/src/main/resources/logback.xml rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/main/resources/manytomany.cfg.xml (98%) create mode 100644 persistence-modules/hibernate-many-to-many/src/main/resources/persistence-h2.properties create mode 100644 persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/SpringContextTest.java rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java (97%) rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java (96%) create mode 100644 persistence-modules/hibernate-many-to-many/src/test/resources/.gitignore create mode 100644 persistence-modules/hibernate-many-to-many/src/test/resources/com/baeldung/hibernate/criteria/model/Item.hbm.xml create mode 100644 persistence-modules/hibernate-many-to-many/src/test/resources/import.sql rename persistence-modules/{spring-hibernate-5 => hibernate-many-to-many}/src/test/resources/manytomany.cfg.xml (100%) diff --git a/persistence-modules/hibernate-many-to-many/.gitignore b/persistence-modules/hibernate-many-to-many/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/persistence-modules/hibernate-many-to-many/README.md b/persistence-modules/hibernate-many-to-many/README.md new file mode 100644 index 0000000000..19b865d4e1 --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/README.md @@ -0,0 +1,7 @@ +## Hibernate 5 with Spring + +This module contains articles about Hibernate 5 with Spring. + +### Relevant articles + +- [Hibernate Many to Many Annotation Tutorial](https://www.baeldung.com/hibernate-many-to-many) \ No newline at end of file diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.fdt b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.fdt new file mode 100644 index 0000000000000000000000000000000000000000..d71a08150212e0d18327d1491c3687976b1c0d38 GIT binary patch literal 160 zcmcD&o+B>fQ<|KbmuhMdT#{dun&Ot3nv+uOmRMZkl30?+z`($mbzSAP`{iOo;d#DB z{fW~w7#bQFnHYE&m>Bf`D==s!=jZArB?2{-=B4XpWG1B+d6=BK3Q y=miwzr<5j_a4;I`Gf2xDfe2#|VFDsd^%=wiK$2#Rj0ZF(zW`bZ2Af23UjYC|kS^)~ literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.fdx b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.fdx new file mode 100644 index 0000000000000000000000000000000000000000..72359255c620cb440b643215ce0e4a85f205da77 GIT binary patch literal 84 zcmcD&o+B>nQ<|KbmuhMdT#{dun&Ot3nv+uOmRMZknU|7U!N9=4m~~y{wfp5_L*aS8 hM*WG?G#Ho|fuamnK+Mp`ctB(F3!o}62&>U62LPU67+U}U literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.fnm b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.fnm new file mode 100644 index 0000000000000000000000000000000000000000..b0143e1ac5e967810feee7771557bca5f71a4922 GIT binary patch literal 532 zcmcD&o+B>gQ<|KbmuhO@mYJH9;+dD0U(CS3z?gMi<+c0eVngA1zDE6t(=-@Z1>!R@ zlTwTF5=&C!lXDV_iy4@h8U8~7lWah05!i%){Nj?#y!2wX{G!~%61_Aq#R0Pfm$Ks0 zw6x3$MgykI6h;~t%Uw{EpHiA!;+L44%EU;0XLF~d7AF^F7L;V>=P}d3e74-w-29?S W7A8ijhxh@F$uEEr4hGV{B@6-GbkQ<|KbmuhP4mtT}y?2=fL$N&Uc*HvD-UoJKjp66@SpEyl}p`^5=qP+Zo P#^e_uX%J`#I_?Dk?LHOl literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.nvm b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.nvm new file mode 100644 index 0000000000000000000000000000000000000000..19f60a39bcf9a121ca3bc1590ba6df45481bf44a GIT binary patch literal 88 zcmcD&o+B>mQ<|KbmuhP4mtT}y?3-GWn37nM$N&Uc*HvD-UoJKjp66@SpEyl}fe9oE b0_Dt%5C((xe<0vLpfULcRDfZE({vpGz#bVo literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.si b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.si new file mode 100644 index 0000000000000000000000000000000000000000..3d537083b422c76bfcef3c42fb25ad1eeb45bf4f GIT binary patch literal 514 zcmZWm-AcnS7+u9~xJ_kF@X}p)F_49(cGKM`sGA6z3LSV^LX*u()08Bwdy8ENUivJ) zgBN=R!3XeC(?5_cA^AAx`_AEzTrB;A<|uMWK)QxaW|Rc-Hkh(fsiZwGkG^j{1#G^L z%>{aEE3TyfJLTW{1{2jsFTm_Yw4hOYMlk|0QJC-DbL9G@b;WqdIFcR<>Uoeh~}|{1}jVe#N8(yQQWik zQ)?at(xar1ultt;i?~bl)UlS{L*z=vHCR=Cd9F=p0Ank05)#pH8}_U&JhRM`Qv+J{ zvSWfE#=0uPOMr}VQl?mDXx?y4r+8<_03j2ZhNfddR`BW=X6}kmC0JuZ?Xa-6Rc?ZZ k9`UglGER{Mlwnf69M}`bei#g{KiaQf$xkNh=X|#K1BMr#*8l(j literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.tvd b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2.tvd new file mode 100644 index 0000000000000000000000000000000000000000..b46c8d109cc2a907cd84fbbf6e87ad51cff7929d GIT binary patch literal 392 zcmW-dze`(D6vxlgC=Ftbkz&VE+Y%kb7xR(~f;J6xskBJ7;&$@h$$eMukH@|D5#1c@ zY@rZ05n3p562ZMwXQ6|CK$p@kP90qA)dSxH-w)?}hwt*0n4W%<$D}A)cuz)dQtY&` zZFC3#!OqpQzpFoOICZ>MJ;Z(mhW4MpC=5S6J3Rp?TztHUHa12|C4al(ec7uGFuV`N zwtdxl{be0L)M|6li$@3D#^4}aXWR8M+x#~3{HS=hKLx>c1%=gFCMeF0A>~LVU5v?S znR1r$L}+IvNp1G5MB}nlE2>6yT!fHycnKzVAHu{-D2z5B46Dsq7;C_JiiUB;x<2JC z{0js+vW_b<#BzbA1vkY!%e3)~^|&EH*1D7{AFu^KP$fq5gc(A&1lJEdWhiiWuVWi1 zZLV0H5@vs(@86~Fa6$8MJKp0e(LK9Ztw#&2BXY@6^4MsryRHdSk84eMcW;8=d*$dQ<|KbmuhMdl3J7-mYQ6WUsUXwmy%k+z`($mbzSAP`{iOo;d#DB{fW~w c7?>D=q6{WL%lQ<|KbmuhMdkY8MqnU`K1UX)pqTI7lQ<|KbmuhMdkY8MqnU`K1UX)pqS_I@V072GumDlcM>D0O1m)+6Xon>a0yL6Ju zPB5UIt(}E`f&YVGdMiQjZ}81-E~Sw9*!Mke-tWy$&h(9yN7^KB4lKX{*up(gi6?}x z*JpSCJpJLeS3f@=zLy_2d(Y|wN*E1Z4#)(+SyRNB1?i()WjRx+P*rY95IW@bkya%{+IS}l zD2zQ8g_$Z19Sd2lrR}*wTHi$UTwPVhhN?R=Ri|!pY zU}+~qDjJ_4PtwPPQ1s#)4eVlYj=Dxd(kyhtg(^aYXnj$PsFP(_UTSb9ySE;6O@d^d4#s+OQVVr!snE98D%uaoJ%K^ar7cF zA>#Ha<=ewOJ{*nN&XA9H2Yfsl(7m=nB9mIqk6AW7hdb7Fq2!f9CDu4|ud%Q3 z)|O}=w*Qa=sf%)2=veIo2S29o{)`q GU*tdZxy^3? literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2_Lucene50_0.tip b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_2_Lucene50_0.tip new file mode 100644 index 0000000000000000000000000000000000000000..9803f1b398829ace933101fbc393ea47807267f3 GIT binary patch literal 195 zcmcD&o+B>ol#`#F9a5B<8j@O+TkM&al3KyQz`&GsUFEg=&diPJQ=d`gp3 z^HNO>;tlM9+L+yfLx9Ry85o(FA2Bg7FfyQtvaZ7>%C`xdDE~WbqC%6vqUOHImHmuB VyFg&+0gcHoAWQ~^%eLE20RSolE8PG9 literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_3.cfe b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_3.cfe new file mode 100644 index 0000000000000000000000000000000000000000..8fb074f30e754beeb8a030f31d07de2babe63b62 GIT binary patch literal 341 zcmcD&o+B>qQ<|KbmuhO@oS$2eUz(TVnpaYknOe*M1X zMK3L-0we_ldJu{sm_;wIECtGGgwodh@i2qq4fG1~!R7(w_CVz$QRGwdlOf`aqEPuf z6#0_OT&R3Agl1A?(JO&j%De=sX$r_CP?aneP{9bGoAY3T6QJ5fKprW9aM)nl8$o75 heaEf})$WhxkOGJ}J5)2n;R70zUqIC|B=Stl1OR>yJ!${| literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_3.cfs b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_3.cfs new file mode 100644 index 0000000000000000000000000000000000000000..e26078b9e7cfbaca6e06ec3cf3156f48d0b92d08 GIT binary patch literal 2119 zcmcIl%TE(Q7@wKl?Nj9~Z^TD}V5}4bjIXK?ltc&#L?Vgcc6Uk_yF1P9Ho&d%ZHikvL|pRoxVQ^K z83{+s+sl-S$2ZRGxRR1B3lRZvSZ<_#keUvHD~?{6F0vg-IFEoEWVdZrCXvvlaVybO zd<3xJbWT_UvQ7y;{ItU=wG>lJ+Zr>3Bf$6RRA=Ul2s+O7`|vvMJrf^(q(=FfsB`Js zdh6tGi|wZ)o5chXa%rs*9YE3nP;9|rzY@LhlP6H+Cg2g^emCA_KJlIwzKdsR=fI@nK?+`vA14I OvhREg-uJeq`PhGT-i literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_3.si b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/_3.si new file mode 100644 index 0000000000000000000000000000000000000000..f2d6b6a030c291e9fdddf28b924e5caad9a02f57 GIT binary patch literal 371 zcmcD&o+B>oQ<|KbmuhMdoSL4SnpfhPmzK}Kz`&SwUFEg=&diPN-zVhpTE zn30i-DZiL2JTosPzr0w%(11HDu`E%qEEUKv67nxfOwLJFaLz9($S+DP$;{8=fl3z@ z13B!5hI$5ihKBqQ!Cas=u(%*pT-#FDCnQ+c(9(o22kbnU0#;K!AY{)k)=Ml(&R|W< zO))bO0UJ_OnpcvUn+j8iX%bs;erZv1Dr;I!X>kS@&;+QREQSVp2Am+h#U+Wk1-yo4 zCZ>iKCPv2Q#-`@XtntQr#hGkCGC8dnLZvdw!^5m3zbG}uEi*MIrPwXMC^xZ0FE>9W cmCMOBI3zwez}3~|fX3t(pr8YRcS#F10cJaIr~m)} literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/segments_5 b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/segments_5 new file mode 100644 index 0000000000000000000000000000000000000000..66a4c385a5adac5ff16e505da6de875fcd295c3d GIT binary patch literal 198 zcmcD&o+HjtoSL4SnpaZHz`($kbzSAP`{iOo;d#DB{fX1G8BJMPS%DHDAOOTHK+FUb zVv09nL{qE5;ZvHNnwM&7@*fI7nqX`g4H9EuiZ@2rtwp?Uh65UtUx3X45?V&3b^sz| BR7L;* literal 0 HcmV?d00001 diff --git a/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/write.lock b/persistence-modules/hibernate-many-to-many/com.baeldung.hibernatesearch.model.Product/write.lock new file mode 100644 index 0000000000..e69de29bb2 diff --git a/persistence-modules/hibernate-many-to-many/pom.xml b/persistence-modules/hibernate-many-to-many/pom.xml new file mode 100644 index 0000000000..6f1abb6a7a --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + hibernate-many-to-many + 0.1-SNAPSHOT + hibernate-many-to-many + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + + org.springframework + spring-context + ${org.springframework.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-aspects + ${org.springframework.version} + + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.springframework.data + spring-data-jpa + ${org.springframework.data.version} + + + org.hibernate + hibernate-core + ${hibernate.version} + + + javax.transaction + jta + ${jta.version} + + + org.hibernate + hibernate-search-orm + ${hibernatesearch.version} + + + org.apache.tomcat + tomcat-dbcp + ${tomcat-dbcp.version} + + + + + com.google.guava + guava + ${guava.version} + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + test + + + org.springframework + spring-test + ${org.springframework.version} + test + + + org.springframework.security + spring-security-test + ${org.springframework.security.version} + test + + + org.hsqldb + hsqldb + ${hsqldb.version} + + + com.h2database + h2 + ${h2.version} + + + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.2 + + + com.sun.xml.bind + jaxb-core + 2.3.0.1 + + + javax.xml.bind + jaxb-api + 2.3.1 + + + com.sun.xml.bind + jaxb-impl + 2.3.1 + + + + + + 5.0.2.RELEASE + 1.10.6.RELEASE + 4.2.1.RELEASE + + 5.2.10.Final + 5.8.2.Final + 9.0.0.M26 + 1.1 + 2.3.4 + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/manytomany/model/Employee.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/hibernate/manytomany/model/Employee.java similarity index 96% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/manytomany/model/Employee.java rename to persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/hibernate/manytomany/model/Employee.java index 8157945e2c..bfe1b5ad29 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/manytomany/model/Employee.java +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/hibernate/manytomany/model/Employee.java @@ -1,88 +1,88 @@ -package com.baeldung.hibernate.manytomany.model; - -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.Table; - -@Entity -@Table(name = "Employee") -public class Employee implements Serializable { - @Id - @Column(name = "employee_id") - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long employeeId; - - @Column(name = "first_name") - private String firstName; - - @Column(name = "last_name") - private String lastName; - - @ManyToMany(cascade = { CascadeType.ALL }) - @JoinTable( - name = "Employee_Project", - joinColumns = { @JoinColumn(name = "employee_id") }, - inverseJoinColumns = { @JoinColumn(name = "project_id") } - ) - Set projects = new HashSet(); - - - public Employee() { - super(); - } - - public Employee(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - public Employee(String firstName, String lastName, Set projects) { - this.firstName = firstName; - this.lastName = lastName; - this.projects = projects; - } - - - public Long getEmployeeId() { - return employeeId; - } - - public void setEmployeeId(Long employeeId) { - this.employeeId = employeeId; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public Set getProjects() { - return projects; - } - - public void setProjects(Set projects) { - this.projects = projects; - } -} +package com.baeldung.hibernate.manytomany.model; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "Employee") +public class Employee implements Serializable { + @Id + @Column(name = "employee_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long employeeId; + + @Column(name = "first_name") + private String firstName; + + @Column(name = "last_name") + private String lastName; + + @ManyToMany(cascade = { CascadeType.ALL }) + @JoinTable( + name = "Employee_Project", + joinColumns = { @JoinColumn(name = "employee_id") }, + inverseJoinColumns = { @JoinColumn(name = "project_id") } + ) + Set projects = new HashSet(); + + + public Employee() { + super(); + } + + public Employee(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(String firstName, String lastName, Set projects) { + this.firstName = firstName; + this.lastName = lastName; + this.projects = projects; + } + + + public Long getEmployeeId() { + return employeeId; + } + + public void setEmployeeId(Long employeeId) { + this.employeeId = employeeId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Set getProjects() { + return projects; + } + + public void setProjects(Set projects) { + this.projects = projects; + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/manytomany/model/Project.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/hibernate/manytomany/model/Project.java similarity index 95% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/manytomany/model/Project.java rename to persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/hibernate/manytomany/model/Project.java index d6c049f33e..c291d7d7af 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/manytomany/model/Project.java +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/hibernate/manytomany/model/Project.java @@ -1,61 +1,61 @@ -package com.baeldung.hibernate.manytomany.model; - -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToMany; -import javax.persistence.Table; - -@Entity -@Table(name = "Project") -public class Project implements Serializable { - - @Id - @Column(name = "project_id") - @GeneratedValue - private Long projectId; - - @Column(name = "title") - private String title; - - @ManyToMany(mappedBy = "projects") - private Set employees = new HashSet(); - - public Project() { - super(); - } - - public Project(String title) { - this.title = title; - } - - public Long getProjectId() { - return projectId; - } - - public void setProjectId(Long projectId) { - this.projectId = projectId; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public Set getEmployees() { - return employees; - } - - public void setEmployees(Set employees) { - this.employees = employees; - } - - -} +package com.baeldung.hibernate.manytomany.model; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "Project") +public class Project implements Serializable { + + @Id + @Column(name = "project_id") + @GeneratedValue + private Long projectId; + + @Column(name = "title") + private String title; + + @ManyToMany(mappedBy = "projects") + private Set employees = new HashSet(); + + public Project() { + super(); + } + + public Project(String title) { + this.title = title; + } + + public Long getProjectId() { + return projectId; + } + + public void setProjectId(Long projectId) { + this.projectId = projectId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Set getEmployees() { + return employees; + } + + public void setEmployees(Set employees) { + this.employees = employees; + } + + +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/manytomany/util/HibernateUtil.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/hibernate/manytomany/util/HibernateUtil.java similarity index 97% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/manytomany/util/HibernateUtil.java rename to persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/hibernate/manytomany/util/HibernateUtil.java index 29e8d7515a..ff035c0c37 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/manytomany/util/HibernateUtil.java +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/hibernate/manytomany/util/HibernateUtil.java @@ -1,45 +1,45 @@ -package com.baeldung.hibernate.manytomany.util; - -import org.hibernate.SessionFactory; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.Configuration; -import org.hibernate.service.ServiceRegistry; -import com.baeldung.hibernate.manytomany.model.Employee; -import com.baeldung.hibernate.manytomany.model.Project; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HibernateUtil { - - private static final Logger LOGGER = LoggerFactory.getLogger(HibernateUtil.class); - private static SessionFactory sessionFactory; - - private static SessionFactory buildSessionFactory() { - try { - // Create the SessionFactory from hibernate-annotation.cfg.xml - Configuration configuration = new Configuration(); - configuration.addAnnotatedClass(Employee.class); - configuration.addAnnotatedClass(Project.class); - configuration.configure("manytomany.cfg.xml"); - LOGGER.debug("Hibernate Annotation Configuration loaded"); - - ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()) - .build(); - LOGGER.debug("Hibernate Annotation serviceRegistry created"); - - SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); - - return sessionFactory; - } catch (Throwable ex) { - LOGGER.error("Initial SessionFactory creation failed.", ex); - throw new ExceptionInInitializerError(ex); - } - } - - public static SessionFactory getSessionFactory() { - if (sessionFactory == null) { - sessionFactory = buildSessionFactory(); - } - return sessionFactory; - } -} +package com.baeldung.hibernate.manytomany.util; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.service.ServiceRegistry; +import com.baeldung.hibernate.manytomany.model.Employee; +import com.baeldung.hibernate.manytomany.model.Project; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HibernateUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(HibernateUtil.class); + private static SessionFactory sessionFactory; + + private static SessionFactory buildSessionFactory() { + try { + // Create the SessionFactory from hibernate-annotation.cfg.xml + Configuration configuration = new Configuration(); + configuration.addAnnotatedClass(Employee.class); + configuration.addAnnotatedClass(Project.class); + configuration.configure("manytomany.cfg.xml"); + LOGGER.debug("Hibernate Annotation Configuration loaded"); + + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()) + .build(); + LOGGER.debug("Hibernate Annotation serviceRegistry created"); + + SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); + + return sessionFactory; + } catch (Throwable ex) { + LOGGER.error("Initial SessionFactory creation failed.", ex); + throw new ExceptionInInitializerError(ex); + } + } + + public static SessionFactory getSessionFactory() { + if (sessionFactory == null) { + sessionFactory = buildSessionFactory(); + } + return sessionFactory; + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/manytomany/spring/PersistenceConfig.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/manytomany/spring/PersistenceConfig.java similarity index 97% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/manytomany/spring/PersistenceConfig.java rename to persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/manytomany/spring/PersistenceConfig.java index b8e7e1b2fd..f7179b07e5 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/manytomany/spring/PersistenceConfig.java +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/manytomany/spring/PersistenceConfig.java @@ -1,70 +1,70 @@ -package com.baeldung.manytomany.spring; - -import java.util.Properties; -import javax.sql.DataSource; -import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; -import org.springframework.orm.hibernate5.HibernateTransactionManager; -import org.springframework.orm.hibernate5.LocalSessionFactoryBean; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; - - - -@Configuration -@EnableTransactionManagement -@PropertySource({ "classpath:persistence-h2.properties" }) -@ComponentScan({ "com.baeldung.hibernate.manytomany" }) -public class PersistenceConfig { - - @Autowired - private Environment env; - - @Bean - public LocalSessionFactoryBean sessionFactory() { - final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); - sessionFactory.setDataSource(restDataSource()); - sessionFactory.setPackagesToScan(new String[] { "com.baeldung.hibernate.manytomany" }); - sessionFactory.setHibernateProperties(hibernateProperties()); - - return sessionFactory; - } - - @Bean - public DataSource restDataSource() { - final BasicDataSource dataSource = new BasicDataSource(); - dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName")); - dataSource.setUrl(env.getProperty("jdbc.url")); - dataSource.setUsername(env.getProperty("jdbc.user")); - dataSource.setPassword(env.getProperty("jdbc.pass")); - - return dataSource; - } - - @Bean - public PlatformTransactionManager hibernateTransactionManager() { - final HibernateTransactionManager transactionManager = new HibernateTransactionManager(); - transactionManager.setSessionFactory(sessionFactory().getObject()); - return transactionManager; - } - - @Bean - public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { - return new PersistenceExceptionTranslationPostProcessor(); - } - - private final Properties hibernateProperties() { - final Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); - hibernateProperties.setProperty("hibernate.show_sql", "false"); - - return hibernateProperties; - } -} +package com.baeldung.manytomany.spring; + +import java.util.Properties; +import javax.sql.DataSource; +import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.orm.hibernate5.HibernateTransactionManager; +import org.springframework.orm.hibernate5.LocalSessionFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + + +@Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-h2.properties" }) +@ComponentScan({ "com.baeldung.hibernate.manytomany" }) +public class PersistenceConfig { + + @Autowired + private Environment env; + + @Bean + public LocalSessionFactoryBean sessionFactory() { + final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); + sessionFactory.setDataSource(restDataSource()); + sessionFactory.setPackagesToScan(new String[] { "com.baeldung.hibernate.manytomany" }); + sessionFactory.setHibernateProperties(hibernateProperties()); + + return sessionFactory; + } + + @Bean + public DataSource restDataSource() { + final BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName")); + dataSource.setUrl(env.getProperty("jdbc.url")); + dataSource.setUsername(env.getProperty("jdbc.user")); + dataSource.setPassword(env.getProperty("jdbc.pass")); + + return dataSource; + } + + @Bean + public PlatformTransactionManager hibernateTransactionManager() { + final HibernateTransactionManager transactionManager = new HibernateTransactionManager(); + transactionManager.setSessionFactory(sessionFactory().getObject()); + return transactionManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + private final Properties hibernateProperties() { + final Properties hibernateProperties = new Properties(); + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + hibernateProperties.setProperty("hibernate.show_sql", "false"); + + return hibernateProperties; + } +} diff --git a/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java new file mode 100644 index 0000000000..5a6c76a93a --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java @@ -0,0 +1,14 @@ +package com.baeldung.persistence.dao.common; + +import java.io.Serializable; + +import com.google.common.base.Preconditions; + +public abstract class AbstractDao implements IOperations { + + protected Class clazz; + + protected final void setClazz(final Class clazzToSet) { + clazz = Preconditions.checkNotNull(clazzToSet); + } +} diff --git a/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java new file mode 100644 index 0000000000..f34866d883 --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java @@ -0,0 +1,59 @@ +package com.baeldung.persistence.dao.common; + +import java.io.Serializable; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import com.google.common.base.Preconditions; + +@SuppressWarnings("unchecked") +public abstract class AbstractHibernateDao extends AbstractDao implements IOperations { + + @Autowired + protected SessionFactory sessionFactory; + + // API + + @Override + public T findOne(final long id) { + return (T) getCurrentSession().get(clazz, id); + } + + @Override + public List findAll() { + return getCurrentSession().createQuery("from " + clazz.getName()).getResultList(); + } + + @Override + public void create(final T entity) { + Preconditions.checkNotNull(entity); + getCurrentSession().saveOrUpdate(entity); + } + + @Override + public T update(final T entity) { + Preconditions.checkNotNull(entity); + return (T) getCurrentSession().merge(entity); + } + + @Override + public void delete(final T entity) { + Preconditions.checkNotNull(entity); + getCurrentSession().delete(entity); + } + + @Override + public void deleteById(final long entityId) { + final T entity = findOne(entityId); + Preconditions.checkState(entity != null); + delete(entity); + } + + protected Session getCurrentSession() { + return sessionFactory.getCurrentSession(); + } + +} \ No newline at end of file diff --git a/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/IOperations.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/IOperations.java new file mode 100644 index 0000000000..4ef99221ab --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/dao/common/IOperations.java @@ -0,0 +1,20 @@ +package com.baeldung.persistence.dao.common; + +import java.io.Serializable; +import java.util.List; + +public interface IOperations { + + T findOne(final long id); + + List findAll(); + + void create(final T entity); + + T update(final T entity); + + void delete(final T entity); + + void deleteById(final long entityId); + +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/IEmployeeDao.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/IEmployeeDao.java similarity index 96% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/IEmployeeDao.java rename to persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/IEmployeeDao.java index d619807b64..5ba018dc52 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/IEmployeeDao.java +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/IEmployeeDao.java @@ -1,8 +1,8 @@ -package com.baeldung.persistence.manytomany.dao; - -import com.baeldung.hibernate.manytomany.model.Employee; -import com.baeldung.persistence.dao.common.IOperations; - -public interface IEmployeeDao extends IOperations{ - -} +package com.baeldung.persistence.manytomany.dao; + +import com.baeldung.hibernate.manytomany.model.Employee; +import com.baeldung.persistence.dao.common.IOperations; + +public interface IEmployeeDao extends IOperations{ + +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/IProjectDao.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/IProjectDao.java similarity index 96% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/IProjectDao.java rename to persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/IProjectDao.java index 4a55714f8d..48fbb8bf6b 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/IProjectDao.java +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/IProjectDao.java @@ -1,8 +1,8 @@ -package com.baeldung.persistence.manytomany.dao; - -import com.baeldung.hibernate.manytomany.model.Project; -import com.baeldung.persistence.dao.common.IOperations; - -public interface IProjectDao extends IOperations{ - -} +package com.baeldung.persistence.manytomany.dao; + +import com.baeldung.hibernate.manytomany.model.Project; +import com.baeldung.persistence.dao.common.IOperations; + +public interface IProjectDao extends IOperations{ + +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/impl/EmployeeDao.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/impl/EmployeeDao.java similarity index 96% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/impl/EmployeeDao.java rename to persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/impl/EmployeeDao.java index b062c00ff9..25fee8c379 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/impl/EmployeeDao.java +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/impl/EmployeeDao.java @@ -1,16 +1,16 @@ -package com.baeldung.persistence.manytomany.dao.impl; - -import org.springframework.stereotype.Repository; -import com.baeldung.hibernate.manytomany.model.Employee; -import com.baeldung.persistence.dao.common.AbstractHibernateDao; -import com.baeldung.persistence.manytomany.dao.IEmployeeDao; - -@Repository -public class EmployeeDao extends AbstractHibernateDao implements IEmployeeDao { - - public EmployeeDao() { - super(); - - setClazz(Employee.class); - } -} +package com.baeldung.persistence.manytomany.dao.impl; + +import org.springframework.stereotype.Repository; +import com.baeldung.hibernate.manytomany.model.Employee; +import com.baeldung.persistence.dao.common.AbstractHibernateDao; +import com.baeldung.persistence.manytomany.dao.IEmployeeDao; + +@Repository +public class EmployeeDao extends AbstractHibernateDao implements IEmployeeDao { + + public EmployeeDao() { + super(); + + setClazz(Employee.class); + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/impl/ProjectDao.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/impl/ProjectDao.java similarity index 96% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/impl/ProjectDao.java rename to persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/impl/ProjectDao.java index 772026fbc1..8fc29a5de3 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/persistence/manytomany/dao/impl/ProjectDao.java +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/persistence/manytomany/dao/impl/ProjectDao.java @@ -1,17 +1,17 @@ -package com.baeldung.persistence.manytomany.dao.impl; - -import org.springframework.stereotype.Repository; -import com.baeldung.hibernate.manytomany.model.Project; -import com.baeldung.persistence.dao.common.AbstractHibernateDao; -import com.baeldung.persistence.manytomany.dao.IProjectDao; - - -@Repository -public class ProjectDao extends AbstractHibernateDao implements IProjectDao { - - public ProjectDao() { - super(); - - setClazz(Project.class); - } -} +package com.baeldung.persistence.manytomany.dao.impl; + +import org.springframework.stereotype.Repository; +import com.baeldung.hibernate.manytomany.model.Project; +import com.baeldung.persistence.dao.common.AbstractHibernateDao; +import com.baeldung.persistence.manytomany.dao.IProjectDao; + + +@Repository +public class ProjectDao extends AbstractHibernateDao implements IProjectDao { + + public ProjectDao() { + super(); + + setClazz(Project.class); + } +} diff --git a/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/spring/PersistenceConfig.java b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/spring/PersistenceConfig.java new file mode 100644 index 0000000000..e1ea3e2024 --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/main/java/com/baeldung/spring/PersistenceConfig.java @@ -0,0 +1,75 @@ +package com.baeldung.spring; + +import com.google.common.base.Preconditions; +import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.orm.hibernate5.HibernateTransactionManager; +import org.springframework.orm.hibernate5.LocalSessionFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; +import java.util.Properties; + +@Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-h2.properties" }) +@ComponentScan({ "com.baeldung.persistence" }) +public class PersistenceConfig { + + @Autowired + private Environment env; + + @Bean + public LocalSessionFactoryBean sessionFactory() { + final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); + sessionFactory.setDataSource(dataSource()); + sessionFactory.setPackagesToScan(new String[] { "com.baeldung.persistence.model" }); + sessionFactory.setHibernateProperties(hibernateProperties()); + + return sessionFactory; + } + + @Bean + public DataSource dataSource() { + final BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public PlatformTransactionManager hibernateTransactionManager() { + final HibernateTransactionManager transactionManager = new HibernateTransactionManager(); + transactionManager.setSessionFactory(sessionFactory().getObject()); + return transactionManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + private final Properties hibernateProperties() { + final Properties hibernateProperties = new Properties(); + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + + hibernateProperties.setProperty("hibernate.show_sql", "false"); + + // Envers properties + hibernateProperties.setProperty("org.hibernate.envers.audit_table_suffix", env.getProperty("envers.audit_table_suffix")); + + return hibernateProperties; + } + +} \ No newline at end of file diff --git a/persistence-modules/hibernate-many-to-many/src/main/resources/import.sql b/persistence-modules/hibernate-many-to-many/src/main/resources/import.sql new file mode 100644 index 0000000000..ae008f29bc --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/main/resources/import.sql @@ -0,0 +1,31 @@ +insert into item (item_id, item_name, item_desc, item_price) +values(1,'item One', 'test 1', 35.12); + +insert into item (item_id, item_name, item_desc, item_price) +values(2,'Pogo stick', 'Pogo stick', 466.12); +insert into item (item_id, item_name, item_desc, item_price) +values(3,'Raft', 'Raft', 345.12); + +insert into item (item_id, item_name, item_desc, item_price) +values(4,'Skate Board', 'Skating', 135.71); + +insert into item (item_id, item_name, item_desc, item_price) +values(5,'Umbrella', 'Umbrella for Rain', 619.25); + +insert into item (item_id, item_name, item_desc, item_price) +values(6,'Glue', 'Glue for home', 432.73); + +insert into item (item_id, item_name, item_desc, item_price) +values(7,'Paint', 'Paint for Room', 1311.40); + +insert into item (item_id, item_name, item_desc, item_price) +values(8,'Red paint', 'Red paint for room', 1135.71); + +insert into item (item_id, item_name, item_desc, item_price) +values(9,'Household Chairs', 'Chairs for house', 25.71); + +insert into item (item_id, item_name, item_desc, item_price) +values(10,'Office Chairs', 'Chairs for office', 395.98); + +insert into item (item_id, item_name, item_desc, item_price) +values(11,'Outdoor Chairs', 'Chairs for outdoor activities', 1234.36); diff --git a/persistence-modules/hibernate-many-to-many/src/main/resources/logback.xml b/persistence-modules/hibernate-many-to-many/src/main/resources/logback.xml new file mode 100644 index 0000000000..ec0dc2469a --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-5/src/main/resources/manytomany.cfg.xml b/persistence-modules/hibernate-many-to-many/src/main/resources/manytomany.cfg.xml similarity index 98% rename from persistence-modules/spring-hibernate-5/src/main/resources/manytomany.cfg.xml rename to persistence-modules/hibernate-many-to-many/src/main/resources/manytomany.cfg.xml index 315e2e3118..d7c8f24fb0 100644 --- a/persistence-modules/spring-hibernate-5/src/main/resources/manytomany.cfg.xml +++ b/persistence-modules/hibernate-many-to-many/src/main/resources/manytomany.cfg.xml @@ -1,15 +1,15 @@ - - - - - com.mysql.jdbc.Driver - tutorialmy5ql - jdbc:mysql://localhost:3306/spring_hibernate_many_to_many - tutorialuser - org.hibernate.dialect.MySQLDialect - thread - false - - + + + + + com.mysql.jdbc.Driver + tutorialmy5ql + jdbc:mysql://localhost:3306/spring_hibernate_many_to_many + tutorialuser + org.hibernate.dialect.MySQLDialect + thread + false + + diff --git a/persistence-modules/hibernate-many-to-many/src/main/resources/persistence-h2.properties b/persistence-modules/hibernate-many-to-many/src/main/resources/persistence-h2.properties new file mode 100644 index 0000000000..e3544d354a --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/main/resources/persistence-h2.properties @@ -0,0 +1,21 @@ +# jdbc.X +jdbc.driverClassName=org.h2.Driver +jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 +jdbc.eventGeneratedId=sa +jdbc.user=sa +jdbc.pass= + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop +hibernate.cache.use_second_level_cache=true +hibernate.cache.use_query_cache=true +hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory + +# hibernate.search.X +hibernate.search.default.directory_provider = filesystem +hibernate.search.default.indexBase = /data/index/default + +# envers.X +envers.audit_table_suffix=_audit_log diff --git a/persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..24c038aeb6 --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/SpringContextTest.java @@ -0,0 +1,19 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + + +import com.baeldung.spring.PersistenceConfig; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java b/persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java similarity index 97% rename from persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java rename to persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java index 614de6d3ad..797d3384a0 100644 --- a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java +++ b/persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java @@ -1,49 +1,49 @@ -package com.baeldung.hibernate.manytomany; - -import java.util.HashSet; -import java.util.Set; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.hibernate.manytomany.model.Employee; -import com.baeldung.hibernate.manytomany.model.Project; -import com.baeldung.manytomany.spring.PersistenceConfig; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) -public class HibernateManyToManyAnnotationJavaConfigMainIntegrationTest { - - @Autowired - private SessionFactory sessionFactory; - - private Session session; - - @Before - public final void before() { - session = sessionFactory.openSession(); - session.beginTransaction(); - } - - @After - public final void after() { - session.getTransaction().commit(); - session.close(); - } - - @Test - public final void whenEntitiesAreCreated_thenNoExceptions() { - Set projects = new HashSet(); - projects.add(new Project("IT Project")); - projects.add(new Project("Networking Project")); - session.persist(new Employee("Peter", "Oven", projects)); - session.persist(new Employee("Allan", "Norman", projects)); - } - -} +package com.baeldung.hibernate.manytomany; + +import java.util.HashSet; +import java.util.Set; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; +import com.baeldung.hibernate.manytomany.model.Employee; +import com.baeldung.hibernate.manytomany.model.Project; +import com.baeldung.manytomany.spring.PersistenceConfig; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +public class HibernateManyToManyAnnotationJavaConfigMainIntegrationTest { + + @Autowired + private SessionFactory sessionFactory; + + private Session session; + + @Before + public final void before() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @After + public final void after() { + session.getTransaction().commit(); + session.close(); + } + + @Test + public final void whenEntitiesAreCreated_thenNoExceptions() { + Set projects = new HashSet(); + projects.add(new Project("IT Project")); + projects.add(new Project("Networking Project")); + session.persist(new Employee("Peter", "Oven", projects)); + session.persist(new Employee("Allan", "Norman", projects)); + } + +} diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java b/persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java similarity index 96% rename from persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java rename to persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java index 0073e181cc..d09b2888df 100644 --- a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java +++ b/persistence-modules/hibernate-many-to-many/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java @@ -1,80 +1,80 @@ -package com.baeldung.hibernate.manytomany; - -import static org.junit.Assert.assertNotNull; -import static junit.framework.TestCase.assertEquals; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.baeldung.hibernate.manytomany.util.HibernateUtil; -import com.baeldung.hibernate.manytomany.model.Employee; -import com.baeldung.hibernate.manytomany.model.Project; - -/** - * Configured in: manytomany.cfg.xml - */ -public class HibernateManyToManyAnnotationMainIntegrationTest { - private static SessionFactory sessionFactory; - - private Session session; - - @BeforeClass - public static void beforeTests() { - sessionFactory = HibernateUtil.getSessionFactory(); - } - - @Before - public void setUp() { - session = sessionFactory.openSession(); - session.beginTransaction(); - } - - @Test - public void givenData_whenInsert_thenCreatesMtoMrelationship() { - String[] employeeData = { "Peter Oven", "Allan Norman" }; - String[] projectData = { "IT Project", "Networking Project" }; - Set projects = new HashSet(); - - for (String proj : projectData) { - projects.add(new Project(proj)); - } - - for (String emp : employeeData) { - Employee employee = new Employee(emp.split(" ")[0], emp.split(" ")[1]); - assertEquals(0, employee.getProjects().size()); - employee.setProjects(projects); - session.persist(employee); - assertNotNull(employee); - } - } - - @Test - public void givenSession_whenRead_thenReturnsMtoMdata() { - @SuppressWarnings("unchecked") - List employeeList = session.createQuery("FROM Employee").list(); - assertNotNull(employeeList); - for(Employee employee : employeeList) { - assertNotNull(employee.getProjects()); - } - } - - @After - public void tearDown() { - session.getTransaction() - .commit(); - session.close(); - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } - -} +package com.baeldung.hibernate.manytomany; + +import static org.junit.Assert.assertNotNull; +import static junit.framework.TestCase.assertEquals; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.baeldung.hibernate.manytomany.util.HibernateUtil; +import com.baeldung.hibernate.manytomany.model.Employee; +import com.baeldung.hibernate.manytomany.model.Project; + +/** + * Configured in: manytomany.cfg.xml + */ +public class HibernateManyToManyAnnotationMainIntegrationTest { + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsert_thenCreatesMtoMrelationship() { + String[] employeeData = { "Peter Oven", "Allan Norman" }; + String[] projectData = { "IT Project", "Networking Project" }; + Set projects = new HashSet(); + + for (String proj : projectData) { + projects.add(new Project(proj)); + } + + for (String emp : employeeData) { + Employee employee = new Employee(emp.split(" ")[0], emp.split(" ")[1]); + assertEquals(0, employee.getProjects().size()); + employee.setProjects(projects); + session.persist(employee); + assertNotNull(employee); + } + } + + @Test + public void givenSession_whenRead_thenReturnsMtoMdata() { + @SuppressWarnings("unchecked") + List employeeList = session.createQuery("FROM Employee").list(); + assertNotNull(employeeList); + for(Employee employee : employeeList) { + assertNotNull(employee.getProjects()); + } + } + + @After + public void tearDown() { + session.getTransaction() + .commit(); + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } + +} diff --git a/persistence-modules/hibernate-many-to-many/src/test/resources/.gitignore b/persistence-modules/hibernate-many-to-many/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/persistence-modules/hibernate-many-to-many/src/test/resources/com/baeldung/hibernate/criteria/model/Item.hbm.xml b/persistence-modules/hibernate-many-to-many/src/test/resources/com/baeldung/hibernate/criteria/model/Item.hbm.xml new file mode 100644 index 0000000000..9e0109aae2 --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/test/resources/com/baeldung/hibernate/criteria/model/Item.hbm.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate-many-to-many/src/test/resources/import.sql b/persistence-modules/hibernate-many-to-many/src/test/resources/import.sql new file mode 100644 index 0000000000..087d62d331 --- /dev/null +++ b/persistence-modules/hibernate-many-to-many/src/test/resources/import.sql @@ -0,0 +1,21 @@ +insert into item (item_id, item_name, item_desc, item_price) values(1,'item One', 'test 1', 35.12); + +insert into item (item_id, item_name, item_desc, item_price) values(2,'Pogo stick', 'Pogo stick', 466.12); + +insert into item (item_id, item_name, item_desc, item_price) values(3,'Raft', 'Raft', 345.12); + +insert into item (item_id, item_name, item_desc, item_price) values(4,'Skate Board', 'Skating', 135.71); + +insert into item (item_id, item_name, item_desc, item_price) values(5,'Umbrella', 'Umbrella for Rain', 619.25); + +insert into item (item_id, item_name, item_desc, item_price) values(6,'Glue', 'Glue for home', 432.73); + +insert into item (item_id, item_name, item_desc, item_price) values(7,'Paint', 'Paint for Room', 1311.40); + +insert into item (item_id, item_name, item_desc, item_price) values(8,'Red paint', 'Red paint for room', 1135.71); + +insert into item (item_id, item_name, item_desc, item_price) values(9,'Household Chairs', 'Chairs for house', 25.71); + +insert into item (item_id, item_name, item_desc, item_price) values(10,'Office Chairs', 'Chairs for office', 395.98); + +insert into item (item_id, item_name, item_desc, item_price) values(11,'Outdoor Chairs', 'Chairs for outdoor activities', 1234.36); diff --git a/persistence-modules/spring-hibernate-5/src/test/resources/manytomany.cfg.xml b/persistence-modules/hibernate-many-to-many/src/test/resources/manytomany.cfg.xml similarity index 100% rename from persistence-modules/spring-hibernate-5/src/test/resources/manytomany.cfg.xml rename to persistence-modules/hibernate-many-to-many/src/test/resources/manytomany.cfg.xml diff --git a/persistence-modules/spring-hibernate-5/README.md b/persistence-modules/spring-hibernate-5/README.md index eff59a0362..9770fe95af 100644 --- a/persistence-modules/spring-hibernate-5/README.md +++ b/persistence-modules/spring-hibernate-5/README.md @@ -4,7 +4,6 @@ This module contains articles about Hibernate 5 with Spring. ### Relevant articles -- [Hibernate Many to Many Annotation Tutorial](https://www.baeldung.com/hibernate-many-to-many) - [Programmatic Transactions in the Spring TestContext Framework](https://www.baeldung.com/spring-test-programmatic-transactions) - [JPA Criteria Queries](https://www.baeldung.com/hibernate-criteria-queries) - [Introduction to Hibernate Search](https://www.baeldung.com/hibernate-search) diff --git a/persistence-modules/spring-hibernate-5/pom.xml b/persistence-modules/spring-hibernate-5/pom.xml index d0fa23504c..bb8c4e8228 100644 --- a/persistence-modules/spring-hibernate-5/pom.xml +++ b/persistence-modules/spring-hibernate-5/pom.xml @@ -108,6 +108,26 @@ h2 ${h2.version} + + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.2 + + + com.sun.xml.bind + jaxb-core + 2.3.0.1 + + + javax.xml.bind + jaxb-api + 2.3.1 + + + com.sun.xml.bind + jaxb-impl + 2.3.1 + diff --git a/persistence-modules/spring-hibernate-5/src/test/resources/import.sql b/persistence-modules/spring-hibernate-5/src/test/resources/import.sql index 087d62d331..52c800f6b4 100644 --- a/persistence-modules/spring-hibernate-5/src/test/resources/import.sql +++ b/persistence-modules/spring-hibernate-5/src/test/resources/import.sql @@ -1,3 +1,4 @@ + insert into item (item_id, item_name, item_desc, item_price) values(1,'item One', 'test 1', 35.12); insert into item (item_id, item_name, item_desc, item_price) values(2,'Pogo stick', 'Pogo stick', 466.12);