memory leak occurs in hibernate while updating bean - java

I am getting error java.lang.OutOfMemoryError: Java heap space while i am updating profile detail of student..
error stack:
Hibernate: select studentbea0_.studentID as studentID7_42_, studentbea0_.studentFullName as studentF2_7_42_, studentbea0_.studentAddress as studentA3_7_42_, studentbea0_.studentCity as studentC4_7_42_, studentbea0_.studentState as studentS5_7_42_, studentbea0_.studentCountry as studentC6_7_42_, studentbea0_.className as className7_42_, studentbea0_.birthDate as birthDate7_42_, studentbea0_.studentContactNo as studentC9_7_42_, studentbea0_.studentPassword as student10_7_42_, studentbea0_.studentFacebookPage as student11_7_42_, studentbea0_.studentEmailId as student12_7_42_, studentbea0_.outsideuser as outside13_7_42_, studentbea0_.studentPhoto as student14_7_42_, studentbea0_.studentResume as student15_7_42_, studentbea0_.schooolName10 as schoool16_7_42_, studentbea0_.board10 as board17_7_42_, studentbea0_.marks10 as marks18_7_42_, studentbea0_.schooolName12 as schoool19_7_42_, studentbea0_.board12 as board20_7_42_, studentbea0_.marks12 as marks21_7_42_, studentbea0_.collegeNameUG as college22_7_42_, studentbea0_.boardUG as boardUG7_42_, studentbea0_.marksUG as marksUG7_42_, studentbea0_.collegeNamePG as college25_7_42_, studentbea0_.boardPG as boardPG7_42_, studentbea0_.marksPG as marksPG7_42_, studentbea0_.technologyknown as technol28_7_42_, studentbea0_.resume as resume7_42_, studentbea0_.date_time as date30_7_42_, studentbea0_.collegeID as collegeID7_42_, studentbea0_.courseID as courseID7_42_, collegebea1_.collegeid as collegeid0_0_, collegebea1_.collegeEmailID as collegeE2_0_0_, collegebea1_.collegename as collegen3_0_0_, collegebea1_.collegeaddress as collegea4_0_0_, collegebea1_.collegecity as collegec5_0_0_, collegebea1_.collegewebsite as collegew6_0_0_, collegebea1_.collegedescription as colleged7_0_0_, collegebea1_.collegecontactno as collegec8_0_0_, collegebea1_.collegepassword as collegep9_0_0_, collegebea1_.collegefacebookPage as college10_0_0_, collegebea1_.collegeState as college11_0_0_, collegebea1_.collegeCountry as college12_0_0_, collegebea1_.date_time as date13_0_0_, collegebea1_.pincode as pincode0_0_, college_co2_.collegeID as collegeID0_44_, college_co2_.college_course_ID as college1_44_, college_co2_.college_course_ID as college1_1_1_, college_co2_.date_time as date2_1_1_, college_co2_.courseID as courseID1_1_, college_co2_.collegeID as collegeID1_1_, testbean3_.collegeID as collegeID0_45_, testbean3_.testID as testID45_, testbean3_.testID as testID9_2_, testbean3_.testfile as testfile9_2_, testbean3_.questionSheet as question3_9_2_, testbean3_.teststatus as teststatus9_2_, testbean3_.totalmMark as totalmMark9_2_, testbean3_.time as time9_2_, testbean3_.type as type9_2_, testbean3_.testName as testName9_2_, testbean3_.examcode as examcode9_2_, testbean3_.description as descrip10_9_2_, testbean3_.students as students9_2_, testbean3_.date_time as date12_9_2_, testbean3_.collegeID as collegeID9_2_, testbean3_.subjectID as subjectID9_2_, testbean3_.facultyID as facultyID9_2_, collegeact4_.collegeID as collegeID0_46_, collegeact4_.sessionID as sessionID46_, collegeact4_.sessionID as sessionID23_3_, collegeact4_.loginTime as loginTime23_3_, collegeact4_.logoutTime as logoutTime23_3_, collegeact4_.ipAddress as ipAddress23_3_, collegeact4_.collegeID as collegeID23_3_, assignment5_.collegeID as collegeID0_47_, assignment5_.assignmentID as assignme1_47_, assignment5_.assignmentID as assignme1_17_4_, assignment5_.assignmentfile as assignme2_17_4_, assignment5_.assignmentstatus as assignme3_17_4_, assignment5_.assignmentName as assignme4_17_4_, assignment5_.description as descript5_17_4_, assignment5_.date_time as date6_17_4_, assignment5_.collegeID as collegeID17_4_, assignment5_.subjectID as subjectID17_4_, assignment5_.facultyID as facultyID17_4_, coursebean6_.courseid as courseid2_5_, coursebean6_.courseName as courseName2_5_, coursebean6_.noofsemester as noofseme3_2_5_, coursebean6_.date_time as date4_2_5_, subjectbea7_.courseID as courseID2_48_, subjectbea7_.subjectid as subjectid48_, subjectbea7_.subjectid as subjectid8_6_, subjectbea7_.subjectName as subjectN2_8_6_, subjectbea7_.semester as semester8_6_, subjectbea7_.practical as practical8_6_, subjectbea7_.date_time as date5_8_6_, subjectbea7_.courseID as courseID8_6_, faculty_su8_.courseID as courseID2_49_, faculty_su8_.faculty_subject_ID as faculty1_49_, faculty_su8_.faculty_subject_ID as faculty1_3_7_, faculty_su8_.date_time as date2_3_7_, faculty_su8_.courseID as courseID3_7_, faculty_su8_.subjectID as subjectID3_7_, faculty_su8_.facultyID as facultyID3_7_, college_co9_.courseID as courseID2_50_, college_co9_.college_course_ID as college1_50_, college_co9_.college_course_ID as college1_1_8_, college_co9_.date_time as date2_1_8_, college_co9_.courseID as courseID1_8_, college_co9_.collegeID as collegeID1_8_, jobcourseb10_.courseID as courseID2_51_, jobcourseb10_.jobcourseid as jobcours1_51_, jobcourseb10_.jobcourseid as jobcours1_26_9_, jobcourseb10_.courseID as courseID26_9_, jobcourseb10_.jobID as jobID26_9_, studentact11_.studentID as studentID7_52_, studentact11_.sessionID as sessionID52_, studentact11_.sessionID as sessionID22_10_, studentact11_.loginTime as loginTime22_10_, studentact11_.logoutTime as logoutTime22_10_, studentact11_.ipAddress as ipAddress22_10_, studentact11_.studentID as studentID22_10_, jobviewbea12_.studentID as studentID7_53_, jobviewbea12_.jobviewid as jobviewid53_, jobviewbea12_.jobviewid as jobviewid27_11_, jobviewbea12_.studentID as studentID27_11_, jobviewbea12_.jobID as jobID27_11_, jobbean13_.jobid as jobid20_12_, jobbean13_.jobtitle as jobtitle20_12_, jobbean13_.companyname as companyn3_20_12_, jobbean13_.description as descript4_20_12_, jobbean13_.experience as experience20_12_, jobbean13_.technologies as technolo6_20_12_, jobbean13_.designation as designat7_20_12_, jobbean13_.salary as salary20_12_, jobbean13_.bonus as bonus20_12_, jobbean13_.cities as cities20_12_, jobbean13_.vacancies as vacancies20_12_, jobbean13_.location as location20_12_, jobbean13_.jobtype as jobtype20_12_, jobbean13_.date_time as date14_20_12_, jobbean13_.recruiterID as recruit15_20_12_, jobbean13_.categoryTypeID as categor16_20_12_, jobbean13_.categoryID as categoryID20_12_, applyjobbe14_.studentID as studentID7_54_, applyjobbe14_.applyjobid as applyjobid54_, applyjobbe14_.applyjobid as applyjobid21_13_, applyjobbe14_.date_time as date2_21_13_, applyjobbe14_.studentID as studentID21_13_, applyjobbe14_.jobID as jobID21_13_, jobbean15_.jobid as jobid20_14_, jobbean15_.jobtitle as jobtitle20_14_, jobbean15_.companyname as companyn3_20_14_, jobbean15_.description as descript4_20_14_, jobbean15_.experience as experience20_14_, jobbean15_.technologies as technolo6_20_14_, jobbean15_.designation as designat7_20_14_, jobbean15_.salary as salary20_14_, jobbean15_.bonus as bonus20_14_, jobbean15_.cities as cities20_14_, jobbean15_.vacancies as vacancies20_14_, jobbean15_.location as location20_14_, jobbean15_.jobtype as jobtype20_14_, jobbean15_.date_time as date14_20_14_, jobbean15_.recruiterID as recruit15_20_14_, jobbean15_.categoryTypeID as categor16_20_14_, jobbean15_.categoryID as categoryID20_14_, likevideob16_.studentID as studentID7_55_, likevideob16_.likevideoid as likevide1_55_, likevideob16_.likevideoid as likevide1_31_15_, likevideob16_.date_time as date2_31_15_, likevideob16_.studentID as studentID31_15_, likevideob16_.videoID as videoID31_15_, videobean17_.videoid as videoid15_16_, videobean17_.videoname as videoname15_16_, videobean17_.description as descript3_15_16_, videobean17_.videopath as videopath15_16_, videobean17_.status as status15_16_, videobean17_.usertype as usertype15_16_, videobean17_.author as author15_16_, videobean17_.tag as tag15_16_, videobean17_.likedby as likedby15_16_, videobean17_.date_time as date10_15_16_, videobean17_.categoryID as categoryID15_16_, commentvid18_.studentID as studentID7_56_, commentvid18_.commentvideoid as commentv1_56_, commentvid18_.commentvideoid as commentv1_32_17_, commentvid18_.date_time as date2_32_17_, commentvid18_.comment as comment32_17_, commentvid18_.studentID as studentID32_17_, commentvid18_.videoID as videoID32_17_, videobean19_.videoid as videoid15_18_, videobean19_.videoname as videoname15_18_, videobean19_.description as descript3_15_18_, videobean19_.videopath as videopath15_18_, videobean19_.status as status15_18_, videobean19_.usertype as usertype15_18_, videobean19_.author as author15_18_, videobean19_.tag as tag15_18_, videobean19_.likedby as likedby15_18_, videobean19_.date_time as date10_15_18_, videobean19_.categoryID as categoryID15_18_, likequoteb20_.studentID as studentID7_57_, likequoteb20_.likequoteid as likequot1_57_, likequoteb20_.likequoteid as likequot1_44_19_, likequoteb20_.date_time as date2_44_19_, likequoteb20_.studentID as studentID44_19_, likequoteb20_.quoteid as quoteid44_19_, quotebean21_.quoteid as quoteid16_20_, quotebean21_.quotename as quotename16_20_, quotebean21_.description as descript3_16_20_, quotebean21_.quotepath as quotepath16_20_, quotebean21_.status as status16_20_, quotebean21_.usertype as usertype16_20_, quotebean21_.author as author16_20_, quotebean21_.date_time as date8_16_20_, quotebean21_.categoryID as categoryID16_20_, commentquo22_.studentID as studentID7_58_, commentquo22_.commentquoteid as commentq1_58_, commentquo22_.commentquoteid as commentq1_43_21_, commentquo22_.date_time as date2_43_21_, commentquo22_.comment as comment43_21_, commentquo22_.studentID as studentID43_21_, commentquo22_.quoteid as quoteid43_21_, quotebean23_.quoteid as quoteid16_22_, quotebean23_.quotename as quotename16_22_, quotebean23_.description as descript3_16_22_, quotebean23_.quotepath as quotepath16_22_, quotebean23_.status as status16_22_, quotebean23_.usertype as usertype16_22_, quotebean23_.author as author16_22_, quotebean23_.date_time as date8_16_22_, quotebean23_.categoryID as categoryID16_22_, likearticl24_.studentID as studentID7_59_, likearticl24_.likearticlesid as likearti1_59_, likearticl24_.likearticlesid as likearti1_38_23_, likearticl24_.date_time as date2_38_23_, likearticl24_.studentID as studentID38_23_, likearticl24_.articlesid as articlesid38_23_, articlesbe25_.articlesid as articlesid14_24_, articlesbe25_.articlesname as articles2_14_24_, articlesbe25_.description as descript3_14_24_, articlesbe25_.articlespath as articles4_14_24_, articlesbe25_.status as status14_24_, articlesbe25_.usertype as usertype14_24_, articlesbe25_.author as author14_24_, articlesbe25_.date_time as date8_14_24_, articlesbe25_.likedby as likedby14_24_, articlesbe25_.categoryID as categoryID14_24_, commentart26_.studentID as studentID7_60_, commentart26_.commentarticlesid as commenta1_60_, commentart26_.commentarticlesid as commenta1_37_25_, commentart26_.date_time as date2_37_25_, commentart26_.comment as comment37_25_, commentart26_.studentID as studentID37_25_, commentart26_.articlesID as articlesID37_25_, articlesbe27_.articlesid as articlesid14_26_, articlesbe27_.articlesname as articles2_14_26_, articlesbe27_.description as descript3_14_26_, articlesbe27_.articlespath as articles4_14_26_, articlesbe27_.status as status14_26_, articlesbe27_.usertype as usertype14_26_, articlesbe27_.author as author14_26_, articlesbe27_.date_time as date8_14_26_, articlesbe27_.likedby as likedby14_26_, articlesbe27_.categoryID as categoryID14_26_, likelifecl28_.studentID as studentID7_61_, likelifecl28_.likelifeclubvideoid as likelife1_61_, likelifecl28_.likelifeclubvideoid as likelife1_29_27_, likelifecl28_.date_time as date2_29_27_, likelifecl28_.studentID as studentID29_27_, likelifecl28_.videoid as videoid29_27_, lifeclubvi29_.videoid as videoid28_28_, lifeclubvi29_.videoname as videoname28_28_, lifeclubvi29_.description as descript3_28_28_, lifeclubvi29_.videopath as videopath28_28_, lifeclubvi29_.status as status28_28_, lifeclubvi29_.usertype as usertype28_28_, lifeclubvi29_.author as author28_28_, lifeclubvi29_.tag as tag28_28_, lifeclubvi29_.likedby as likedby28_28_, lifeclubvi29_.date_time as date10_28_28_, lifeclubvi29_.categoryID as categoryID28_28_, commentlif30_.studentID as studentID7_62_, commentlif30_.commentlifeclubvideoid as commentl1_62_, commentlif30_.commentlifeclubvideoid as commentl1_30_29_, commentlif30_.date_time as date2_30_29_, commentlif30_.comment as comment30_29_, commentlif30_.studentID as studentID30_29_, commentlif30_.videoid as videoid30_29_, lifeclubvi31_.videoid as videoid28_30_, lifeclubvi31_.videoname as videoname28_30_, lifeclubvi31_.description as descript3_28_30_, lifeclubvi31_.videopath as videopath28_30_, lifeclubvi31_.status as status28_30_, lifeclubvi31_.usertype as usertype28_30_, lifeclubvi31_.author as author28_30_, lifeclubvi31_.tag as tag28_30_, lifeclubvi31_.likedby as likedby28_30_, lifeclubvi31_.date_time as date10_28_30_, lifeclubvi31_.categoryID as categoryID28_30_, likeebookb32_.studentID as studentID7_63_, likeebookb32_.likeebookid as likeeboo1_63_, likeebookb32_.likeebookid as likeeboo1_33_31_, likeebookb32_.date_time as date2_33_31_, likeebookb32_.studentID as studentID33_31_, likeebookb32_.ebookID as ebookID33_31_, ebookbean33_.ebookid as ebookid13_32_, ebookbean33_.ebookname as ebookname13_32_, ebookbean33_.description as descript3_13_32_, ebookbean33_.ebookpath as ebookpath13_32_, ebookbean33_.status as status13_32_, ebookbean33_.usertype as usertype13_32_, ebookbean33_.author as author13_32_, ebookbean33_.likedby as likedby13_32_, ebookbean33_.date_time as date9_13_32_, ebookbean33_.categoryID as categoryID13_32_, commentebo34_.studentID as studentID7_64_, commentebo34_.commentebookid as commente1_64_, commentebo34_.commentebookid as commente1_34_33_, commentebo34_.date_time as date2_34_33_, commentebo34_.comment as comment34_33_, commentebo34_.studentID as studentID34_33_, commentebo34_.ebookID as ebookID34_33_, ebookbean35_.ebookid as ebookid13_34_, ebookbean35_.ebookname as ebookname13_34_, ebookbean35_.description as descript3_13_34_, ebookbean35_.ebookpath as ebookpath13_34_, ebookbean35_.status as status13_34_, ebookbean35_.usertype as usertype13_34_, ebookbean35_.author as author13_34_, ebookbean35_.likedby as likedby13_34_, ebookbean35_.date_time as date9_13_34_, ebookbean35_.categoryID as categoryID13_34_, submitassi36_.studentID as studentID7_65_, submitassi36_.submitassignmentid as submitas1_65_, submitassi36_.submitassignmentid as submitas1_18_35_, submitassi36_.date_time as date2_18_35_, submitassi36_.message as message18_35_, submitassi36_.assignmentfile as assignme4_18_35_, submitassi36_.studentID as studentID18_35_, submitassi36_.assignmentID as assignme6_18_35_, assignment37_.assignmentID as assignme1_17_36_, assignment37_.assignmentfile as assignme2_17_36_, assignment37_.assignmentstatus as assignme3_17_36_, assignment37_.assignmentName as assignme4_17_36_, assignment37_.description as descript5_17_36_, assignment37_.date_time as date6_17_36_, assignment37_.collegeID as collegeID17_36_, assignment37_.subjectID as subjectID17_36_, assignment37_.facultyID as facultyID17_36_, helpinghan38_.studentID as studentID7_66_, helpinghan38_.helpinghandID as helpingh1_66_, helpinghan38_.helpinghandID as helpingh1_46_37_, helpinghan38_.date_time as date2_46_37_, helpinghan38_.lastpostby as lastpostby46_37_, helpinghan38_.title as title46_37_, helpinghan38_.post as post46_37_, helpinghan38_.category as category46_37_, helpinghan38_.studentID as studentID46_37_, viewhelpin39_.helpinghandID as helpingh4_46_67_, viewhelpin39_.viewhelpinghandpostID as viewhelp1_67_, viewhelpin39_.viewhelpinghandpostID as viewhelp1_45_38_, viewhelpin39_.date_time as date2_45_38_, viewhelpin39_.studentID as studentID45_38_, viewhelpin39_.helpinghandID as helpingh4_45_38_, commenthel40_.helpinghandID as helpingh5_46_68_, commenthel40_.CommenthelpinghandpostID as Commenth1_68_, commenthel40_.CommenthelpinghandpostID as Commenth1_47_39_, commenthel40_.date_time as date2_47_39_, commenthel40_.comment as comment47_39_, commenthel40_.studentID as studentID47_39_, commenthel40_.helpinghandID as helpingh5_47_39_, viewhelpin41_.studentID as studentID7_69_, viewhelpin41_.viewhelpinghandpostID as viewhelp1_69_, viewhelpin41_.viewhelpinghandpostID as viewhelp1_45_40_, viewhelpin41_.date_time as date2_45_40_, viewhelpin41_.studentID as studentID45_40_, viewhelpin41_.helpinghandID as helpingh4_45_40_, commenthel42_.studentID as studentID7_70_, commenthel42_.CommenthelpinghandpostID as Commenth1_70_, commenthel42_.CommenthelpinghandpostID as Commenth1_47_41_, commenthel42_.date_time as date2_47_41_, commenthel42_.comment as comment47_41_, commenthel42_.studentID as studentID47_41_, commenthel42_.helpinghandID as helpingh5_47_41_ from student studentbea0_ inner join college collegebea1_ on studentbea0_.collegeID=collegebea1_.collegeid left outer join college_course college_co2_ on collegebea1_.collegeid=college_co2_.collegeID left outer join test testbean3_ on collegebea1_.collegeid=testbean3_.collegeID left outer join collegeactivitylog collegeact4_ on collegebea1_.collegeid=collegeact4_.collegeID left outer join assignment assignment5_ on collegebea1_.collegeid=assignment5_.collegeID inner join course coursebean6_ on studentbea0_.courseID=coursebean6_.courseid left outer join subject subjectbea7_ on coursebean6_.courseid=subjectbea7_.courseID left outer join faculty_subject faculty_su8_ on coursebean6_.courseid=faculty_su8_.courseID left outer join college_course college_co9_ on coursebean6_.courseid=college_co9_.courseID left outer join Job_Course jobcourseb10_ on coursebean6_.courseid=jobcourseb10_.courseID left outer join studentactivitylog studentact11_ on studentbea0_.studentID=studentact11_.studentID left outer join Job_View jobviewbea12_ on studentbea0_.studentID=jobviewbea12_.studentID left outer join job jobbean13_ on jobviewbea12_.jobID=jobbean13_.jobid left outer join applyjob applyjobbe14_ on studentbea0_.studentID=applyjobbe14_.studentID left outer join job jobbean15_ on applyjobbe14_.jobID=jobbean15_.jobid left outer join like_video likevideob16_ on studentbea0_.studentID=likevideob16_.studentID left outer join video videobean17_ on likevideob16_.videoID=videobean17_.videoid left outer join comment_video commentvid18_ on studentbea0_.studentID=commentvid18_.studentID left outer join video videobean19_ on commentvid18_.videoID=videobean19_.videoid left outer join like_quote likequoteb20_ on studentbea0_.studentID=likequoteb20_.studentID left outer join quote quotebean21_ on likequoteb20_.quoteid=quotebean21_.quoteid left outer join comment_quote commentquo22_ on studentbea0_.studentID=commentquo22_.studentID left outer join quote quotebean23_ on commentquo22_.quoteid=quotebean23_.quoteid left outer join like_articles likearticl24_ on studentbea0_.studentID=likearticl24_.studentID left outer join articles articlesbe25_ on likearticl24_.articlesid=articlesbe25_.articlesid left outer join comment_articles commentart26_ on studentbea0_.studentID=commentart26_.studentID left outer join articles articlesbe27_ on commentart26_.articlesID=articlesbe27_.articlesid left outer join like_lifeclubvideo likelifecl28_ on studentbea0_.studentID=likelifecl28_.studentID left outer join lifeclubvideo lifeclubvi29_ on likelifecl28_.videoid=lifeclubvi29_.videoid left outer join comment_lifeclubvideo commentlif30_ on studentbea0_.studentID=commentlif30_.studentID left outer join lifeclubvideo lifeclubvi31_ on commentlif30_.videoid=lifeclubvi31_.videoid left outer join like_ebook likeebookb32_ on studentbea0_.studentID=likeebookb32_.studentID left outer join ebook ebookbean33_ on likeebookb32_.ebookID=ebookbean33_.ebookid left outer join comment_ebook commentebo34_ on studentbea0_.studentID=commentebo34_.studentID left outer join ebook ebookbean35_ on commentebo34_.ebookID=ebookbean35_.ebookid left outer join submitassignment submitassi36_ on studentbea0_.studentID=submitassi36_.studentID left outer join assignment assignment37_ on submitassi36_.assignmentID=assignment37_.assignmentID left outer join helpinghand helpinghan38_ on studentbea0_.studentID=helpinghan38_.studentID left outer join ViewHelpingHandPostBean viewhelpin39_ on helpinghan38_.helpinghandID=viewhelpin39_.helpinghandID left outer join CommentHelpingHandPostBean commenthel40_ on helpinghan38_.helpinghandID=commenthel40_.helpinghandID left outer join ViewHelpingHandPostBean viewhelpin41_ on studentbea0_.studentID=viewhelpin41_.studentID left outer join CommentHelpingHandPostBean commenthel42_ on studentbea0_.studentID=commenthel42_.studentID where studentbea0_.studentID=?
Exception in thread "http-bio-8080-exec-9" java.lang.OutOfMemoryError: Java heap space
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1361)
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2333)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:435)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2040)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1443)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1777)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1403)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:802)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3293)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
at com.dao.StudentService.updateEducationStudentProfile(StudentService.java:469)
at com.controller.Student.UpdateStudentProfileServlet.service(UpdateStudentProfileServlet.java:76)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
is it because of studentbean has many fields?
sometimes they give error "containerbackgroundprocessor".
This is happen only while i am updating studentprofile..

What is your JVM heap settings now ?
How much data do you load from the DB?
Try
-Xms 512m -Xmx 1028m -XX:PermSize=128m -XX:MaxPermSize=512m

Related

How to prevent Hibernate to load collection with back reference when I need only count()

The goal is to count collection elements without initializing collection. I made it work in some way, but it's not the soulution that I'd say I want.
Back reference is needed because each Price gets some data from Article while being indexed by Hibernate Search.
Join column gives me an option to have only two tables, avoiding 3rd linking table.
#Entity #Indexed
class Article {
String name;
#JsonManagedReference
#OneToMany
#LazyCollection(org.hibernate.annotations.LazyCollectionOption.EXTRA)
#JoinColumn(name = "article_id")
#Field(...bridge = #FieldBridge(impl = PriceBridge.class))
Set<Price> prices;
private User created;
private User updated;
}
#Entity #Indexed
class Price {
#Reference #JsonBackReference
#ManyToOne(fetch=FetchType.LAZY)
#Field(...bridge = #FieldBridge(impl = PriceArticleBridge.class))
private Article article;
#ManyToOne private Provider provider;
#ManyToOne private CustomCurrency currency;
private BigDecimal amount;
private User created;
private User updated;
}
This setup gives me 2 tables where Price table has article_id and there is no 3rd table for linking purposes. But while loading Article and issuing prices.size(), the whole collection is fetched. This is not good because many other entities are loaded too: Provider from Price and User many times because Provider also has its own 2 properties of User to track creator and updater.
When there is no #JoinColumn, 3rd linking table is created and then it starts to use COUNT() instead of loading the whole collection.
My only question is:
How can I keep only 2 tables and use .size() without loading the whole collection?
SQL example when not having #JoinColumn:
select count(prices_id) from article_prices where article_id =?
SQL example when having #JoinColumn (11 tables joined):
SELECT
prices0_.article_id AS article14_18_0_,
prices0_.id AS id1_18_0_,
prices0_.id AS id1_18_1_,
prices0_.date_created AS date_cre2_18_1_,
prices0_.date_last_update AS date_las3_18_1_,
prices0_.created_by_id AS created12_18_1_,
prices0_.last_update_by_id AS last_up13_18_1_,
prices0_.amount AS amount4_18_1_,
prices0_.article_id AS article14_18_1_,
prices0_.availability AS availabi5_18_1_,
prices0_.currency_id AS currenc15_18_1_,
prices0_.description AS descript6_18_1_,
prices0_.local_date_time_valid_from AS local_da7_18_1_,
prices0_.local_date_time_valid_to AS local_da8_18_1_,
prices0_.price_url AS price_ur9_18_1_,
prices0_.provider_id AS provide16_18_1_,
prices0_.purchase_url AS purchas10_18_1_,
prices0_.zone_id_valid_from_to AS zone_id11_18_1_,
user1_.id AS id1_27_2_,
user1_.date_created AS date_cre2_27_2_,
user1_.date_last_update AS date_las3_27_2_,
user1_.created_by_id AS created13_27_2_,
user1_.last_update_by_id AS last_up14_27_2_,
user1_.display_name AS display_4_27_2_,
user1_.failed_login_attempts AS failed_l5_27_2_,
user1_.full_name AS full_nam6_27_2_,
user1_.note AS note7_27_2_,
user1_.object_status AS object_s8_27_2_,
user1_.password AS password9_27_2_,
user1_.phone AS phone10_27_2_,
user1_.time_zone_id AS time_zo11_27_2_,
user1_.username AS usernam12_27_2_,
user2_.id AS id1_27_3_,
user2_.date_created AS date_cre2_27_3_,
user2_.date_last_update AS date_las3_27_3_,
user2_.created_by_id AS created13_27_3_,
user2_.last_update_by_id AS last_up14_27_3_,
user2_.display_name AS display_4_27_3_,
user2_.failed_login_attempts AS failed_l5_27_3_,
user2_.full_name AS full_nam6_27_3_,
user2_.note AS note7_27_3_,
user2_.object_status AS object_s8_27_3_,
user2_.password AS password9_27_3_,
user2_.phone AS phone10_27_3_,
user2_.time_zone_id AS time_zo11_27_3_,
user2_.username AS usernam12_27_3_,
user3_.id AS id1_27_4_,
user3_.date_created AS date_cre2_27_4_,
user3_.date_last_update AS date_las3_27_4_,
user3_.created_by_id AS created13_27_4_,
user3_.last_update_by_id AS last_up14_27_4_,
user3_.display_name AS display_4_27_4_,
user3_.failed_login_attempts AS failed_l5_27_4_,
user3_.full_name AS full_nam6_27_4_,
user3_.note AS note7_27_4_,
user3_.object_status AS object_s8_27_4_,
user3_.password AS password9_27_4_,
user3_.phone AS phone10_27_4_,
user3_.time_zone_id AS time_zo11_27_4_,
user3_.username AS usernam12_27_4_,
user4_.id AS id1_27_5_,
user4_.date_created AS date_cre2_27_5_,
user4_.date_last_update AS date_las3_27_5_,
user4_.created_by_id AS created13_27_5_,
user4_.last_update_by_id AS last_up14_27_5_,
user4_.display_name AS display_4_27_5_,
user4_.failed_login_attempts AS failed_l5_27_5_,
user4_.full_name AS full_nam6_27_5_,
user4_.note AS note7_27_5_,
user4_.object_status AS object_s8_27_5_,
user4_.password AS password9_27_5_,
user4_.phone AS phone10_27_5_,
user4_.time_zone_id AS time_zo11_27_5_,
user4_.username AS usernam12_27_5_,
customcurr5_.id AS id1_9_6_,
customcurr5_.date_created AS date_cre2_9_6_,
customcurr5_.date_last_update AS date_las3_9_6_,
customcurr5_.created_by_id AS created10_9_6_,
customcurr5_.last_update_by_id AS last_up11_9_6_,
customcurr5_.is_default AS is_defau4_9_6_,
customcurr5_.is_reference AS is_refer5_9_6_,
customcurr5_.java_currency AS java_cur6_9_6_,
customcurr5_.object_status AS object_s7_9_6_,
customcurr5_.sign_position AS sign_pos8_9_6_,
customcurr5_.val AS val9_9_6_,
user6_.id AS id1_27_7_,
user6_.date_created AS date_cre2_27_7_,
user6_.date_last_update AS date_las3_27_7_,
user6_.created_by_id AS created13_27_7_,
user6_.last_update_by_id AS last_up14_27_7_,
user6_.display_name AS display_4_27_7_,
user6_.failed_login_attempts AS failed_l5_27_7_,
user6_.full_name AS full_nam6_27_7_,
user6_.note AS note7_27_7_,
user6_.object_status AS object_s8_27_7_,
user6_.password AS password9_27_7_,
user6_.phone AS phone10_27_7_,
user6_.time_zone_id AS time_zo11_27_7_,
user6_.username AS usernam12_27_7_,
user7_.id AS id1_27_8_,
user7_.date_created AS date_cre2_27_8_,
user7_.date_last_update AS date_las3_27_8_,
user7_.created_by_id AS created13_27_8_,
user7_.last_update_by_id AS last_up14_27_8_,
user7_.display_name AS display_4_27_8_,
user7_.failed_login_attempts AS failed_l5_27_8_,
user7_.full_name AS full_nam6_27_8_,
user7_.note AS note7_27_8_,
user7_.object_status AS object_s8_27_8_,
user7_.password AS password9_27_8_,
user7_.phone AS phone10_27_8_,
user7_.time_zone_id AS time_zo11_27_8_,
user7_.username AS usernam12_27_8_,
provider8_.id AS id1_20_9_,
provider8_.date_created AS date_cre2_20_9_,
provider8_.date_last_update AS date_las3_20_9_,
provider8_.created_by_id AS created23_20_9_,
provider8_.last_update_by_id AS last_up24_20_9_,
provider8_.text_id_map AS text_id_4_20_9_,
provider8_.address_search_aid AS address_5_20_9_,
provider8_.alternate_country_id AS alterna25_20_9_,
provider8_.city_id AS city_id26_20_9_,
provider8_.lat AS lat6_20_9_,
provider8_.lng AS lng7_20_9_,
provider8_.street_line1 AS street_l8_20_9_,
provider8_.street_line2 AS street_l9_20_9_,
provider8_.zip AS zip10_20_9_,
provider8_.company_status AS company11_20_9_,
provider8_.compassion_level AS compass12_20_9_,
provider8_.emails AS emails13_20_9_,
provider8_.phones AS phones14_20_9_,
provider8_.social_media AS social_15_20_9_,
provider8_.urls AS urls16_20_9_,
provider8_.description AS descrip17_20_9_,
provider8_.importance AS importa18_20_9_,
provider8_.name AS name19_20_9_,
provider8_.object_status AS object_20_20_9_,
provider8_.parent_id AS parent_27_20_9_,
provider8_.search_aid AS search_21_20_9_,
provider8_.short_name AS short_n22_20_9_,
user9_.id AS id1_27_10_,
user9_.date_created AS date_cre2_27_10_,
user9_.date_last_update AS date_las3_27_10_,
user9_.created_by_id AS created13_27_10_,
user9_.last_update_by_id AS last_up14_27_10_,
user9_.display_name AS display_4_27_10_,
user9_.failed_login_attempts AS failed_l5_27_10_,
user9_.full_name AS full_nam6_27_10_,
user9_.note AS note7_27_10_,
user9_.object_status AS object_s8_27_10_,
user9_.password AS password9_27_10_,
user9_.phone AS phone10_27_10_,
user9_.time_zone_id AS time_zo11_27_10_,
user9_.username AS usernam12_27_10_,
user10_.id AS id1_27_11_,
user10_.date_created AS date_cre2_27_11_,
user10_.date_last_update AS date_las3_27_11_,
user10_.created_by_id AS created13_27_11_,
user10_.last_update_by_id AS last_up14_27_11_,
user10_.display_name AS display_4_27_11_,
user10_.failed_login_attempts AS failed_l5_27_11_,
user10_.full_name AS full_nam6_27_11_,
user10_.note AS note7_27_11_,
user10_.object_status AS object_s8_27_11_,
user10_.password AS password9_27_11_,
user10_.phone AS phone10_27_11_,
user10_.time_zone_id AS time_zo11_27_11_,
user10_.username AS usernam12_27_11_
FROM price_info prices0_
LEFT OUTER JOIN veg_user user1_ ON prices0_.created_by_id=user1_.id
LEFT OUTER JOIN veg_user user2_ ON user1_.created_by_id=user2_.id
LEFT OUTER JOIN veg_user user3_ ON user1_.last_update_by_id=user3_.id
LEFT OUTER JOIN veg_user user4_ ON prices0_.last_update_by_id=user4_.id
LEFT OUTER JOIN custom_currency customcurr5_ ON prices0_.currency_id=customcurr5_.id
LEFT OUTER JOIN veg_user user6_ ON customcurr5_.created_by_id=user6_.id
LEFT OUTER JOIN veg_user user7_ ON customcurr5_.last_update_by_id=user7_.id
LEFT OUTER JOIN provider provider8_ ON prices0_.provider_id=provider8_.id
LEFT OUTER JOIN veg_user user9_ ON provider8_.created_by_id=user9_.id
LEFT OUTER JOIN veg_user user10_ ON provider8_.last_update_by_id=user10_.id
WHERE prices0_.article_id = ?
Not sure about your objectives, however sometime following trick could help:
public class Article {
...
Set<Price> prices;
#Formula("select count(*) from price where article_id=:id")
private int priceCount;
public int getPriceCount() {
if (Hibernate.isInitialized(prices)) {
return prices == null ? 0 : prices.size();
}
return priceCount;
}
}

Performance issue with Criteria API

I am doing a dynamic query using Criteria API, the problem I have is that when this query is executed, each query is repeated for each of the records returned by the query (this is shown by the Hibernate console). Then I get very high response times.
My specification class is as follows:
public class PacienteSpecification implements Specification<Paciente> {
private Paciente filter;
public PacienteSpecification(Paciente filter) {
super();
this.filter = filter;
}
public Predicate toPredicate(Root<Paciente> root, CriteriaQuery<?> cq,
CriteriaBuilder cb) {
Predicate p = cb.conjunction();
p.getExpressions().add(cb.equal(root.get("eliminado"), "N"));
if (filter.getNombres() != "") {
p.getExpressions().add(cb.like(cb.upper(root.get("nombres")), "%" + filter.getNombres().toUpperCase() + "%"));
}
if(filter.getApePaterno() != "") {
p.getExpressions().add(cb.or(cb.like(cb.upper(root.get("apePaterno")), "%" + filter.getApePaterno().toUpperCase() + "%")));
}
if(filter.getApeMaterno() != "") {
p.getExpressions().add(cb.or(cb.like(cb.upper(root.get("apeMaterno")), "%" + filter.getApeMaterno().toUpperCase() + "%")));
}
if (filter.getFicha() != "") {
p.getExpressions().add(cb.equal(cb.upper(root.get("ficha")), filter.getFicha()));
}
if(filter.getFechaNacimiento() != null){
p.getExpressions().add(cb.equal(root.get("fechaNacimiento"), filter.getFechaNacimiento()));
}
if(filter.getGenero() != null){
p.getExpressions().add(cb.equal(root.get("genero"), filter.getGenero()));
}
return p;
}
}
My service that calls the repository is as follows:
List<Paciente> listaPacientes = new ArrayList<Paciente>();
Specification<PacienteDoc> pacienteDocEspecificacion = new PacienteDocEspecification(pacBusqueda.getPacienteDocs().get(0));
final List<PacienteDoc> pacDoc = pacienteDocRep.findAll(pacienteDocEspecificacion);
and when making the service call the hibernate console shows me a query for each record:
Hibernate: select pacientedo0_.id_paciente_doc as id_paciente_doc1_44_, pacientedo0_.eliminado as eliminado2_44_, pacientedo0_.fecha_creacion as fecha_creacion3_44_, pacientedo0_.fecha_ult_modificacion as fecha_ult_modifica4_44_, pacientedo0_.id_usuario_creacion as id_usuario_creacio5_44_, pacientedo0_.id_usuario_ult_mod as id_usuario_ult_mod6_44_, pacientedo0_.num_documento as num_documento7_44_, pacientedo0_.id_paciente as id_paciente8_44_, pacientedo0_.id_tipo_documento as id_tipo_documento9_44_ from dgs_core.paciente_doc pacientedo0_ where 1=1
Hibernate: select paciente0_.id_paciente as id_paciente1_43_0_, paciente0_.ape_materno as ape_materno2_43_0_, paciente0_.ape_paterno as ape_paterno3_43_0_, paciente0_.celular as celular4_43_0_, paciente0_.id_comuna as id_comuna19_43_0_, paciente0_.direccion as direccion5_43_0_, paciente0_.eliminado as eliminado6_43_0_, paciente0_.email as email7_43_0_, paciente0_.id_estado_civil as id_estado_civil20_43_0_, paciente0_.id_etnia as id_etnia21_43_0_, paciente0_.fecha_creacion as fecha_creacion8_43_0_, paciente0_.fecha_defuncion as fecha_defuncion9_43_0_, paciente0_.fecha_nacimiento as fecha_nacimiento10_43_0_, paciente0_.fecha_ult_modificacion as fecha_ult_modific11_43_0_, paciente0_.ficha as ficha12_43_0_, paciente0_.fono as fono13_43_0_, paciente0_.fono_emergencia as fono_emergencia14_43_0_, paciente0_.id_genero as id_genero22_43_0_, paciente0_.id_unidad_creacion as id_unidad_creacio15_43_0_, paciente0_.id_usuario_creacion as id_usuario_creaci16_43_0_, paciente0_.id_usuario_ult_mod as id_usuario_ult_mo17_43_0_, paciente0_.id_nacionalidad as id_nacionalidad23_43_0_, paciente0_.nombres as nombres18_43_0_, paciente0_.id_prevision as id_prevision24_43_0_, paciente0_.id_profesion as id_profesion25_43_0_, catalogo1_.id_catalogo as id_catalogo1_35_1_, catalogo1_.activo as activo2_35_1_, catalogo1_.comentario as comentario3_35_1_, catalogo1_.id_def_catalogo as id_def_catalogo14_35_1_, catalogo1_.orden as orden4_35_1_, catalogo1_.valido_desde as valido_desde5_35_1_, catalogo1_.valido_hasta as valido_hasta6_35_1_, catalogo1_.valor1 as valor7_35_1_, catalogo1_.valor2 as valor8_35_1_, catalogo1_.valor3 as valor9_35_1_, catalogo1_.valor4 as valor10_35_1_, catalogo1_.valor5 as valor11_35_1_, catalogo1_.valor6 as valor12_35_1_, catalogo1_.version as version13_35_1_, definicion2_.id_def_catalogo as id_def_catalogo1_36_2_, definicion2_.activo as activo2_36_2_, definicion2_.columna1 as columna3_36_2_, definicion2_.columna2 as columna4_36_2_, definicion2_.columna3 as columna5_36_2_, definicion2_.columna4 as columna6_36_2_, definicion2_.columna5 as columna7_36_2_, definicion2_.columna6 as columna8_36_2_, definicion2_.comentario as comentario9_36_2_, definicion2_.nombre_catalogo as nombre_catalogo10_36_2_, definicion2_.valido_desde as valido_desde11_36_2_, definicion2_.valido_hasta as valido_hasta12_36_2_, definicion2_.version as version13_36_2_, catalogo3_.id_catalogo as id_catalogo1_35_3_, catalogo3_.activo as activo2_35_3_, catalogo3_.comentario as comentario3_35_3_, catalogo3_.id_def_catalogo as id_def_catalogo14_35_3_, catalogo3_.orden as orden4_35_3_, catalogo3_.valido_desde as valido_desde5_35_3_, catalogo3_.valido_hasta as valido_hasta6_35_3_, catalogo3_.valor1 as valor7_35_3_, catalogo3_.valor2 as valor8_35_3_, catalogo3_.valor3 as valor9_35_3_, catalogo3_.valor4 as valor10_35_3_, catalogo3_.valor5 as valor11_35_3_, catalogo3_.valor6 as valor12_35_3_, catalogo3_.version as version13_35_3_, catalogo4_.id_catalogo as id_catalogo1_35_4_, catalogo4_.activo as activo2_35_4_, catalogo4_.comentario as comentario3_35_4_, catalogo4_.id_def_catalogo as id_def_catalogo14_35_4_, catalogo4_.orden as orden4_35_4_, catalogo4_.valido_desde as valido_desde5_35_4_, catalogo4_.valido_hasta as valido_hasta6_35_4_, catalogo4_.valor1 as valor7_35_4_, catalogo4_.valor2 as valor8_35_4_, catalogo4_.valor3 as valor9_35_4_, catalogo4_.valor4 as valor10_35_4_, catalogo4_.valor5 as valor11_35_4_, catalogo4_.valor6 as valor12_35_4_, catalogo4_.version as version13_35_4_, catalogo5_.id_catalogo as id_catalogo1_35_5_, catalogo5_.activo as activo2_35_5_, catalogo5_.comentario as comentario3_35_5_, catalogo5_.id_def_catalogo as id_def_catalogo14_35_5_, catalogo5_.orden as orden4_35_5_, catalogo5_.valido_desde as valido_desde5_35_5_, catalogo5_.valido_hasta as valido_hasta6_35_5_, catalogo5_.valor1 as valor7_35_5_, catalogo5_.valor2 as valor8_35_5_, catalogo5_.valor3 as valor9_35_5_, catalogo5_.valor4 as valor10_35_5_, catalogo5_.valor5 as valor11_35_5_, catalogo5_.valor6 as valor12_35_5_, catalogo5_.version as version13_35_5_, catalogo6_.id_catalogo as id_catalogo1_35_6_, catalogo6_.activo as activo2_35_6_, catalogo6_.comentario as comentario3_35_6_, catalogo6_.id_def_catalogo as id_def_catalogo14_35_6_, catalogo6_.orden as orden4_35_6_, catalogo6_.valido_desde as valido_desde5_35_6_, catalogo6_.valido_hasta as valido_hasta6_35_6_, catalogo6_.valor1 as valor7_35_6_, catalogo6_.valor2 as valor8_35_6_, catalogo6_.valor3 as valor9_35_6_, catalogo6_.valor4 as valor10_35_6_, catalogo6_.valor5 as valor11_35_6_, catalogo6_.valor6 as valor12_35_6_, catalogo6_.version as version13_35_6_, catalogo7_.id_catalogo as id_catalogo1_35_7_, catalogo7_.activo as activo2_35_7_, catalogo7_.comentario as comentario3_35_7_, catalogo7_.id_def_catalogo as id_def_catalogo14_35_7_, catalogo7_.orden as orden4_35_7_, catalogo7_.valido_desde as valido_desde5_35_7_, catalogo7_.valido_hasta as valido_hasta6_35_7_, catalogo7_.valor1 as valor7_35_7_, catalogo7_.valor2 as valor8_35_7_, catalogo7_.valor3 as valor9_35_7_, catalogo7_.valor4 as valor10_35_7_, catalogo7_.valor5 as valor11_35_7_, catalogo7_.valor6 as valor12_35_7_, catalogo7_.version as version13_35_7_, catalogo8_.id_catalogo as id_catalogo1_35_8_, catalogo8_.activo as activo2_35_8_, catalogo8_.comentario as comentario3_35_8_, catalogo8_.id_def_catalogo as id_def_catalogo14_35_8_, catalogo8_.orden as orden4_35_8_, catalogo8_.valido_desde as valido_desde5_35_8_, catalogo8_.valido_hasta as valido_hasta6_35_8_, catalogo8_.valor1 as valor7_35_8_, catalogo8_.valor2 as valor8_35_8_, catalogo8_.valor3 as valor9_35_8_, catalogo8_.valor4 as valor10_35_8_, catalogo8_.valor5 as valor11_35_8_, catalogo8_.valor6 as valor12_35_8_, catalogo8_.version as version13_35_8_ from dgs_core.paciente paciente0_ left outer join dgs_core.catalogo catalogo1_ on paciente0_.id_comuna=catalogo1_.id_catalogo left outer join dgs_core.definicion_catalogo definicion2_ on catalogo1_.id_def_catalogo=definicion2_.id_def_catalogo left outer join dgs_core.catalogo catalogo3_ on paciente0_.id_estado_civil=catalogo3_.id_catalogo left outer join dgs_core.catalogo catalogo4_ on paciente0_.id_etnia=catalogo4_.id_catalogo left outer join dgs_core.catalogo catalogo5_ on paciente0_.id_genero=catalogo5_.id_catalogo left outer join dgs_core.catalogo catalogo6_ on paciente0_.id_nacionalidad=catalogo6_.id_catalogo left outer join dgs_core.catalogo catalogo7_ on paciente0_.id_prevision=catalogo7_.id_catalogo left outer join dgs_core.catalogo catalogo8_ on paciente0_.id_profesion=catalogo8_.id_catalogo where paciente0_.id_paciente=?
It seems that Your entity mapping is more or less sth like this:
public class Paciente {
...
#OneToMany(fetch=FetchType.EAGER)
private Set<PacienteDoc> docs = new HashSet<>();
...
}
And then You run into What is the "N+1 selects problem" in ORM (Object-Relational Mapping)?
To fix that simply change #OneToMany(fetch=FetchType.EAGER) to #OneToMany which is equal to #OneToMany(fetch=FetchType.LAZY)

EclipseLink - Subqueries with Criteria Query (JPA)

take the following two tables as given:
Objects with columns objId, objTaxonId
Taxa with columns taxId, taxValidSynonymId, taxName (Note Taxa is plural for Taxon)
if a Taxon is valid, its id and validSynonymId are identical, otherwise they are different. To find all synonyms of a Taxon you 'only' need to find all Taxa where the taxValidSynonymId is filled with the taxId of the valid Taxon
how can i gain all Objects where the Taxon has a given Name (including their Synonyms?)
in SQL this is done in a few lines (and Minutes)
SELECT *
FROM Objects
WHERE objTaxonId IN (
SELECT taxId
FROM Taxa
WHERE taxName LIKE 'Test Taxon 1'
OR taxSynIdTaxon IN(
SELECT taxId
FROM Taxa
WHERE taxName LIKE 'Test Taxon 1'
)
)
i was able to work out the inside part, where i gain the list of Taxa and its Synonyms. Now i need to transform this Query to a Subquery...
String NAME_LIKE = "Test Taxon 1";
EntityManager em = EntityManagerProvider.getEntityManager("TestDB"); // get the EntityManager
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaxonImpl> cqObject = cb.createQuery(TaxonImpl.class);//
Root<TaxonImpl> taxonRoot = cqObject.from(TaxonImpl.class);//
Expression<String> taxon_name = taxonRoot.<String> get("taxName");
Predicate where = cb.equal(taxon_name, NAME_LIKE);
// subquery
Subquery<Integer> subQuery = cqObject.subquery(Integer.class);
Root<TaxonImpl> subRoot = subQuery.from(clsImpl);
subQuery.select(subRoot.<Integer> get("taxId"));
subQuery.where(cb.equal(subRoot.<String> get("taxName"), NAME_LIKE));
where = cb.or(where, taxonRoot.get("taxValidSynonymId").in(subQuery));
cqObject.where(where);
Query query = em.createQuery(cqObject);
List<TaxonImpl> result = query.getResultList();
NOTE: the Taxon is Mapped as an many to One relation (target-entity is TaxonImpl)
in my actual application the code (from the subquery) will be dynamically, so a Native Query does not help me.
i figured out how to "transform" the subquery into a query but Eclipselink threw me two errors
the first was forbidden access via field, when i tried the in on a result of TaxonImpl (i tried that first, as in my mapping files the Taxon is mapped as Entity.
so after this i tried to form the SQL 1:1 to JPA.
but Eclipselink generated something weird:
SELECT t0.objIdObject, t0.objAdminCreated, t0.objAdminCreator, t0.objAdminEdited, t0.objAdminEditor, t0.objAdminImport1, t0.objAdminImport2, t0.objAddBool1, t0.objAddBool2, t0.objAddBool3, t0.objAddBool4, t0.objAddBool5, t0.objAddDateTime1, t0.objAddDateTime2, t0.objCommonComments, t0.objCommonDescription, t0.objCommonKeywords, t0.objCommonName, t0.objCommonPublished, t0.objCommonPublishedAs, t0.objCommonStatus, t0.objCommonType, t0.objCommonTypustype, t0.objDetAccuracy, t0.objDetCf, t0.objDetComments, t0.objDetDate, t0.objDetMethod, t0.objDetResult, t0.objAddFloat1, t0.objAddFloat2, t0.objAddFloat3, t0.objAddFloat4, t0.objAddFloat5, t0.objEventAbundance, t0.objEventCollectionMethod, t0.objEventComments, t0.objEventMoreContacts, t0.objEventDateDay1, t0.objEventDate1, t0.objEventDateMonth1, t0.objEventDate2, t0.objEventDateUncertain, t0.objEventDateYear1, t0.objEventEcosystem, t0.objEventHabitat, t0.objEventNumber, t0.objEventPermission, t0.objEventSubstratum, t0.objEventTime1, t0.objEventTime2, t0.objEventWeekNumber, t0.objFlora, t0.objGuidObject, t0.objIOComments, t0.objIODeAccessed, t0.objAddInt1, t0.objAddInt2, t0.objAddInt3, t0.objAddInt4, t0.objAddInt5, t0.objStorageForeignNumber, t0.objStorageNumber, t0.objStorageNumberInCollection, t0.objStorageNumberOld, t0.objStorageNumberPrefix, t0.objAddLkp1, t0.objAddLkp10, t0.objAddLkp2, t0.objAddLkp3, t0.objAddLkp4, t0.objAddLkp5, t0.objAddLkp6, t0.objAddLkp7, t0.objAddLkp8, t0.objAddLkp9, t0.objAddLkpCs1, t0.objAddLkpCs10, t0.objAddLkpCs11, t0.objAddLkpCs12, t0.objAddLkpCs13, t0.objAddLkpCs14, t0.objAddLkpCs15, t0.objAddLkpCs2, t0.objAddLkpCs3, t0.objAddLkpCs4, t0.objAddLkpCs5, t0.objAddLkpCs6, t0.objAddLkpCs7, t0.objAddLkpCs8, t0.objAddLkpCs9, t0.objOriginAccessionDate, t0.objOriginAccessionNumber, t0.objOriginComments, t0.objOriginMoreContacts, t0.objOriginSource, t0.objOriginType, t0.objPreparationComments, t0.objPreparationDate, t0.objPreparationType, t0.objPropAdults, t0.objPropAge, t0.objPropAgeUnit, t0.objPropEggs, t0.objPropFemale, t0.objPropHeight, t0.objPropHeightUnit, t0.objPropJuveniles, t0.objPropLarvae, t0.objPropLength, t0.objPropLengthUnit, t0.objPropMale, t0.objPropObservation, t0.objPropObservationComments, t0.objPropPupae, t0.objPropSex, t0.objPropStadium, t0.objPropWeight, t0.objPropWeightUnit, t0.objPropWidth, t0.objPropWidthUnit, t0.objSiteComments, t0.objStorageComments, t0.objStorageContainerNumber, t0.objStorageContainerPieces, t0.objStorageContainerType, t0.objStorageLevel1, t0.objStorageLevel2, t0.objStorageLevel3, t0.objStorageLevel4, t0.objStorageLevel5, t0.objStorageNumberInContainer, t0.objstoragePieces, t0.objStorageValue, t0.objStorageValueUnit, t0.objAddText1, t0.objAddText10, t0.objAddText2, t0.objAddText3, t0.objAddText4, t0.objAddText5, t0.objAddText6, t0.objAddText7, t0.objAddText8, t0.objAddText9, t0.objIdCollection, t0.objCommonIdReference, t0.objDetIdContact, t0.objDetIdReference, t0.objEventIdContact, t0.objIdExcursion, t0.objOriginIdContact, t0.objPreparationIdContact, t0.objIdProject, t0.objSiteIdSite, t0.objdetIdTaxon
FROM tObjects t0
WHERE t0.objdetIdTaxon IN (
SELECT t1.taxIdTaxon.t1.taxIdTaxon
FROM tTaxa t1
WHERE (t1.taxTaxonDisplay LIKE 'Test Taxon 1'
OR t1.taxSynIdTaxon IN (
SELECT t2.taxSynIdTaxon
FROM tTaxa t2
WHERE t2.taxTaxonDisplay LIKE 'Test Taxon 1')))
to take out the error:
SELECT t1.taxIdTaxon.t1.taxIdTaxon
which is complete crap. you cannot execute a function on an type of int!
resolving this error (BUG?) introduces a new construct (which still returns the same results)
SELECT t1.objIdObject, t1.objAdminCreated, t1.objAdminCreator, t1.objAdminEdited, t1.objAdminEditor, t1.objAdminImport1, t1.objAdminImport2, t1.objAddBool1, t1.objAddBool2, t1.objAddBool3, t1.objAddBool4, t1.objAddBool5, t1.objAddDateTime1, t1.objAddDateTime2, t1.objCommonComments, t1.objCommonDescription, t1.objCommonKeywords, t1.objCommonName, t1.objCommonPublished, t1.objCommonPublishedAs, t1.objCommonStatus, t1.objCommonType, t1.objCommonTypustype, t1.objDetAccuracy, t1.objDetCf, t1.objDetComments, t1.objDetDate, t1.objDetMethod, t1.objDetResult, t1.objAddFloat1, t1.objAddFloat2, t1.objAddFloat3, t1.objAddFloat4, t1.objAddFloat5, t1.objEventAbundance, t1.objEventCollectionMethod, t1.objEventComments, t1.objEventMoreContacts, t1.objEventDateDay1, t1.objEventDate1, t1.objEventDateMonth1, t1.objEventDate2, t1.objEventDateUncertain, t1.objEventDateYear1, t1.objEventEcosystem, t1.objEventHabitat, t1.objEventNumber, t1.objEventPermission, t1.objEventSubstratum, t1.objEventTime1, t1.objEventTime2, t1.objEventWeekNumber, t1.objFlora, t1.objGuidObject, t1.objIOComments, t1.objIODeAccessed, t1.objAddInt1, t1.objAddInt2, t1.objAddInt3, t1.objAddInt4, t1.objAddInt5, t1.objStorageForeignNumber, t1.objStorageNumber, t1.objStorageNumberInCollection, t1.objStorageNumberOld, t1.objStorageNumberPrefix, t1.objAddLkp1, t1.objAddLkp10, t1.objAddLkp2, t1.objAddLkp3, t1.objAddLkp4, t1.objAddLkp5, t1.objAddLkp6, t1.objAddLkp7, t1.objAddLkp8, t1.objAddLkp9, t1.objAddLkpCs1, t1.objAddLkpCs10, t1.objAddLkpCs11, t1.objAddLkpCs12, t1.objAddLkpCs13, t1.objAddLkpCs14, t1.objAddLkpCs15, t1.objAddLkpCs2, t1.objAddLkpCs3, t1.objAddLkpCs4, t1.objAddLkpCs5, t1.objAddLkpCs6, t1.objAddLkpCs7, t1.objAddLkpCs8, t1.objAddLkpCs9, t1.objOriginAccessionDate, t1.objOriginAccessionNumber, t1.objOriginComments, t1.objOriginMoreContacts, t1.objOriginSource, t1.objOriginType, t1.objPreparationComments, t1.objPreparationDate, t1.objPreparationType, t1.objPropAdults, t1.objPropAge, t1.objPropAgeUnit, t1.objPropEggs, t1.objPropFemale, t1.objPropHeight, t1.objPropHeightUnit, t1.objPropJuveniles, t1.objPropLarvae, t1.objPropLength, t1.objPropLengthUnit, t1.objPropMale, t1.objPropObservation, t1.objPropObservationComments, t1.objPropPupae, t1.objPropSex, t1.objPropStadium, t1.objPropWeight, t1.objPropWeightUnit, t1.objPropWidth, t1.objPropWidthUnit, t1.objSiteComments, t1.objStorageComments, t1.objStorageContainerNumber, t1.objStorageContainerPieces, t1.objStorageContainerType, t1.objStorageLevel1, t1.objStorageLevel2, t1.objStorageLevel3, t1.objStorageLevel4, t1.objStorageLevel5, t1.objStorageNumberInContainer, t1.objstoragePieces, t1.objStorageValue, t1.objStorageValueUnit, t1.objAddText1, t1.objAddText10, t1.objAddText2, t1.objAddText3, t1.objAddText4, t1.objAddText5, t1.objAddText6, t1.objAddText7, t1.objAddText8, t1.objAddText9, t1.objIdCollection, t1.objCommonIdReference, t1.objDetIdContact, t1.objDetIdReference, t1.objEventIdContact, t1.objIdExcursion, t1.objOriginIdContact, t1.objPreparationIdContact, t1.objIdProject, t1.objSiteIdSite, t1.objdetIdTaxon
FROM tTaxa t0, tObjects t1
WHERE (
t0.taxIdTaxon IN (
SELECT t2.taxIdTaxon
FROM tTaxa t2
WHERE (t2.taxTaxonDisplay LIKE 'Test Taxon 1'
OR t2.taxSynIdTaxon IN (
SELECT t3.taxSynIdTaxon
FROM tTaxa t3
WHERE t3.taxTaxonDisplay LIKE 'Test Taxon 1'
)
)
) AND (t0.taxIdTaxon = t1.objdetIdTaxon)
)
this seems strange to me, but it is working - and it is faster than my alternative query, which includes a inner join
NOTE: Eclipselink does ignore the JoinType. regardless what you pass it takes an left outer join. (documentation says something else!)
finally i provide the two examples for join and joinless
private static Predicate addSynonymsWithJoins(Root<BioObjectImpl> r, CriteriaBuilder b, CriteriaQuery cq,
Attribute attr, Path path, Object value) {
Join taxJoin = r.join(BioObjectEnum.taxon.name(), JoinType.INNER);
Path<Object> taxValidSynonymId = taxJoin.get(TaxonEnum.validSynonymId.name());
Subquery<TaxonImpl> innerSubquery = cq.subquery(TaxonImpl.class);
Root fromSubTax = innerSubquery.from(TaxonImpl.class);
innerSubquery.select(fromSubTax.<Integer> get(TaxonEnum.id.name()));
Predicate dynamic1 = cb.like(fromSubTax.get(TaxonEnum.name.name()),
NAME_LIKE);
innerSubquery.where(dynamic1);
Predicate dynamic2 = resolveComparator(b, attr, taxJoin.get(attr.getPropertyName()), attr.getValue());//
Predicate p = b.or(taxValidSynonymId.in(innerSubquery), dynamic2);
return p;
}
private static Predicate addSynonymsWithoutJoins(Root<BioObjectImpl> r, CriteriaBuilder b, CriteriaQuery cq,
Attribute attr, Path path, Object value) {
cq.select(r);
Path<Integer> objTaxonId = r.<Integer> get(BioObjectEnum.taxon.name()).get(TaxonEnum.id.name());
Subquery<Integer> t2 = cq.subquery(Integer.class);
Root<TaxonImpl> t2fromTaxon = t2.from(TaxonImpl.class);
Path<Integer> t2taxId = t2fromTaxon.<Integer> get(TaxonEnum.validSynonymId.name());
t2.select(t2taxId);
Predicate t2dynamicWhere = resolveComparator(b, attr, t2fromTaxon.get(attr.getPropertyName()), attr.getValue());
t2.where(t2dynamicWhere);
Subquery<Integer> t1 = cq.subquery(Integer.class);
Root<TaxonImpl> t1fromTaxon = t1.from(TaxonImpl.class);
Predicate t1dynamicWhere = b.like(fromSubTax.get(TaxonEnum.name.name()),
NAME_LIKE);
Path<Integer> t1Select = t1fromTaxon.<Integer> get(TaxonEnum.id.name());
t1.select(t1Select);
Path<Integer> t1TaxSynonymId = t1fromTaxon.<Integer> get(TaxonEnum.validSynonymId.name());
t1dynamicWhere = b.or(t1dynamicWhere, t1TaxSynonymId.in(t2));
t1.where(t1dynamicWhere);
Predicate where = objTaxonId.in(t1);
return where;
}

Postgresql infinite loop after a hibernate criteria list

I'm stucked with a database problem for several days now. The application hangs after a specific hibernate criteria.list(). Exactly by the following stacktrace:
java.net.SocketInputStream.read(byte[], int, int)
org.postgresql.core.VisibleBufferedInputStream.readMore(int)
org.postgresql.core.VisibleBufferedInputStream.ensureBytes(int)
org.postgresql.core.VisibleBufferedInputStream.read()
org.postgresql.core.PGStream.ReceiveChar()
org.postgresql.core.v3.QueryExecutorImpl.processResults(ResultHandler, int)
org.postgresql.core.v3.QueryExecutorImpl.execute(Query, ParameterList, ResultHandler, int, int, int)
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(Query, ParameterList, int)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(int)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery()
org.hibernate.internal.CriteriaImpl.list()
After some researches and tests I found that the problem is not a blocking query, but a query that is executed forever.
It's a java spring application with the following sessionFactory and transaction manager configuration:
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/database" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.myapp.domain" />
<property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
The underlying database is PostgreSQL and here is the current hibernate configuration
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hbm2ddl.auto">none</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache">true</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="show_sql">false</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">false</property>
<property name="order_updates">true</property>
</session-factory>
</hibernate-configuration>
The critical area in the code is:
private void fillEmptyNames() throws CablewatchException {
List<Device> devicesList = deviceDao.getDevices();
if (devicesList != null) {
for (Device device : devicesList {
String name = deviceDao.getDeviceName(device.getModule().getObjectIdentifier(), device.getSubrack(), device.getSlot());
...
}
}
}
The application hangs on the second dao function "getDeviceName". which is implemented as follow:
#Transactional(timeout=30)
public String getDeviceName(long moduleId, int subrackNr, int slotNr) throws CablewatchException {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Device.class).add(Restrictions.eq("module.objectIdentifier", moduleId)).add(Restrictions.eq("subrack",subrackNr)).add(Restrictions.eq("slot",slotNr)).addOrder(Order.desc("objectIdentifier")).setMaxResults(1);
List<Device> devicesList = criteria.list();
if (devicesList != null && !devicesList.isEmpty() && devicesList.get(0) instanceof Device) {
Device device = devicesList.get(0);
return device.getName();
}
return null;
}
Also a detail I'm confronted with is that the same passage works fine under Windows, so currently the problem is only happening on Linux.
UPDATE:
The generated query is:
select
this_.objectIdentifier as objectId1_0_9_,
this_.ackId as ackId11_0_9_,
this_.alarmInfoId as alarmIn12_0_9_,
this_.cleared as cleared2_0_9_,
this_.clearedTime as clearedT3_0_9_,
this_.logIndex as logIndex4_0_9_,
this_.module as module5_0_9_,
this_.neId as neId13_0_9_,
this_.occurenceTime as occurenc6_0_9_,
this_.serial as serial7_0_9_,
this_.severityId as severit14_0_9_,
this_.slot as slot8_0_9_,
this_.subrack as subrack9_0_9_,
this_.value as value10_0_9_,
acknowledg2_.objectIdentifier as objectId1_2_0_,
acknowledg2_.comment as comment2_2_0_,
acknowledg2_.username as username3_2_0_,
alarminfo3_.objectIdentifier as objectId1_1_1_,
alarminfo3_.cw_alarmMessage as cw_alarm2_1_1_,
alarminfo3_.cw_alarmOid as cw_alarm3_1_1_,
ne4_.OBJECTIDENTIFIER as OBJECTID1_8_2_,
ne4_.cw_neActive as cw_neAct2_8_2_,
ne4_.cw_neCategory as cw_neCat3_8_2_,
ne4_.cw_neFirmware as cw_neFir4_8_2_,
ne4_.cw_neHasWebInterface as cw_neHas5_8_2_,
ne4_.cw_neInetAddress as cw_neIne6_8_2_,
ne4_.cw_neInfo as cw_neInf7_8_2_,
ne4_.cw_neMacAddress as cw_neMac8_8_2_,
ne4_.cw_neModel as cw_neMod9_8_2_,
ne4_.cw_neName as cw_neNa10_8_2_,
ne4_.cw_neSerial as cw_neSe11_8_2_,
ne4_.cw_neSysDescription as cw_neSy12_8_2_,
ne4_.cw_neType as cw_neTy13_8_2_,
ne4_.cw_installationDate as cw_inst14_8_2_,
ne4_.cw_instance as cw_inst15_8_2_,
ne4_.cw_lastAlarmLogIndex as cw_last16_8_2_,
ne4_.cw_locationId as cw_loca19_8_2_,
ne4_.cw_readCommunity as cw_read17_8_2_,
ne4_.cw_severityId as cw_seve20_8_2_,
ne4_.cw_writeCommunity as cw_writ18_8_2_,
location5_.objectIdentifier as objectId1_5_3_,
location5_.cw_imageName as cw_image2_5_3_,
location5_.cw_locationCity as cw_locat3_5_3_,
location5_.cw_locationCode as cw_locat4_5_3_,
location5_.cw_locationContact as cw_locat5_5_3_,
location5_.cw_locationDescription1 as cw_locat6_5_3_,
location5_.cw_locationDescription2 as cw_locat7_5_3_,
location5_.cw_locationName as cw_locat8_5_3_,
location5_.cw_locationStreet as cw_locat9_5_3_,
location5_.cw_locationType as cw_loca10_5_3_,
location5_.cw_parentLocationId as cw_pare11_5_3_,
location5_.cw_severityId as cw_seve12_5_3_,
location5_.cw_sublocationSeverityId as cw_subl13_5_3_,
location6_.objectIdentifier as objectId1_5_4_,
location6_.cw_imageName as cw_image2_5_4_,
location6_.cw_locationCity as cw_locat3_5_4_,
location6_.cw_locationCode as cw_locat4_5_4_,
location6_.cw_locationContact as cw_locat5_5_4_,
location6_.cw_locationDescription1 as cw_locat6_5_4_,
location6_.cw_locationDescription2 as cw_locat7_5_4_,
location6_.cw_locationName as cw_locat8_5_4_,
location6_.cw_locationStreet as cw_locat9_5_4_,
location6_.cw_locationType as cw_loca10_5_4_,
location6_.cw_parentLocationId as cw_pare11_5_4_,
location6_.cw_severityId as cw_seve12_5_4_,
location6_.cw_sublocationSeverityId as cw_subl13_5_4_,
severity7_.id as id1_15_5_,
severity7_.cw_severityColor as cw_sever2_15_5_,
severity7_.cw_severityName as cw_sever3_15_5_,
severity8_.id as id1_15_6_,
severity8_.cw_severityColor as cw_sever2_15_6_,
severity8_.cw_severityName as cw_sever3_15_6_,
severity9_.id as id1_15_7_,
severity9_.cw_severityColor as cw_sever2_15_7_,
severity9_.cw_severityName as cw_sever3_15_7_,
severity10_.id as id1_15_8_,
severity10_.cw_severityColor as cw_sever2_15_8_,
severity10_.cw_severityName as cw_sever3_15_8_
from
CW_ALARM this_
left outer join
CW_Acknowledgment acknowledg2_
on this_.ackId=acknowledg2_.objectIdentifier
left outer join
CW_ALARMINFO alarminfo3_
on this_.alarmInfoId=alarminfo3_.objectIdentifier
left outer join
CW_NE ne4_
on this_.neId=ne4_.OBJECTIDENTIFIER
left outer join
CW_LOCATION location5_
on ne4_.cw_locationId=location5_.objectIdentifier
left outer join
CW_LOCATION location6_
on location5_.cw_parentLocationId=location6_.objectIdentifier
left outer join
CW_SEVERITY severity7_
on location6_.cw_severityId=severity7_.id
left outer join
CW_SEVERITY severity8_
on location6_.cw_sublocationSeverityId=severity8_.id
left outer join
CW_SEVERITY severity9_
on ne4_.cw_severityId=severity9_.id
left outer join
CW_SEVERITY severity10_
on this_.severityId=severity10_.id
where
this_.neId=?
and this_.subrack=?
and this_.slot=?
and this_.module<>?
order by
this_.objectIdentifier desc limit ?
I executed it from pgAdmin (and replaced the parameters with their values) and it works fine. Below is the query plan:
"Limit (cost=25819.66..25819.66 rows=1 width=1185)"
" -> Sort (cost=25819.66..25819.66 rows=1 width=1185)"
" Sort Key: this_.objectidentifier"
" -> Nested Loop Left Join (cost=0.00..25819.65 rows=1 width=1185)"
" -> Nested Loop Left Join (cost=0.00..25811.37 rows=1 width=1021)"
" -> Nested Loop Left Join (cost=0.00..25803.09 rows=1 width=857)"
" -> Nested Loop Left Join (cost=0.00..25799.21 rows=1 width=693)"
" -> Nested Loop Left Join (cost=0.00..25795.33 rows=1 width=529)"
" -> Nested Loop Left Join (cost=0.00..25793.45 rows=1 width=464)"
" Join Filter: (ne4_.cw_locationid = location5_.objectidentifier)"
" -> Nested Loop Left Join (cost=0.00..25791.22 rows=1 width=399)"
" Join Filter: (this_.neid = ne4_.objectidentifier)"
" -> Nested Loop Left Join (cost=0.00..25788.76 rows=1 width=225)"
" -> Nested Loop Left Join (cost=0.00..25780.48 rows=1 width=150)"
" Join Filter: (this_.ackid = acknowledg2_.objectidentifier)"
" -> Seq Scan on cw_alarm this_ (cost=0.00..25779.32 rows=1 width=132)"
" Filter: (((module)::text <> ''::text) AND (neid = 471) AND (subrack = (-1)) AND (slot = (-1)))"
" -> Seq Scan on cw_acknowledgment acknowledg2_ (cost=0.00..1.07 rows=7 width=18)"
" -> Index Scan using cw_alarminfo_pkey on cw_alarminfo alarminfo3_ (cost=0.00..8.27 rows=1 width=75)"
" Index Cond: (this_.alarminfoid = objectidentifier)"
" -> Seq Scan on cw_ne ne4_ (cost=0.00..2.45 rows=1 width=174)"
" Filter: (objectidentifier = 471)"
" -> Seq Scan on cw_location location5_ (cost=0.00..2.10 rows=10 width=65)"
" -> Index Scan using cw_location_pkey on cw_location location6_ (cost=0.00..1.87 rows=1 width=65)"
" Index Cond: (location5_.cw_parentlocationid = objectidentifier)"
" -> Index Scan using cw_severity_pkey on cw_severity severity7_ (cost=0.00..3.87 rows=1 width=164)"
" Index Cond: (location6_.cw_severityid = id)"
" -> Index Scan using cw_severity_pkey on cw_severity severity8_ (cost=0.00..3.87 rows=1 width=164)"
" Index Cond: (location6_.cw_sublocationseverityid = id)"
" -> Index Scan using cw_severity_pkey on cw_severity severity9_ (cost=0.00..8.27 rows=1 width=164)"
" Index Cond: (ne4_.cw_severityid = id)"
" -> Index Scan using cw_severity_pkey on cw_severity severity10_ (cost=0.00..8.27 rows=1 width=164)"
" Index Cond: (this_.severityid = id)"
Following the detail about Linux and Windows version, I've tried the same test but instead of the local database postgresql_9.1.13 (Debian) I used a remote access to postgresql_9.3.5(Windows) and installed and tried postgresql_9.1.13(Windows). Both worked correctly.
I also tried the same code from my Windows system to the remote postgresql_9.1.13(Debian) and another machine with a remote postgresql_9.1.15(Debian). In both cases the problem occurs.
It seems the problem could lay on the Linux version of postgresql_9.1.x.
Thanks in advance.
After debugging the database with the commands Craig and Clemens provided me (display current queries, pg_stat_activity, explain analyze select, pg_locks etc.), I found out that it isn't an infinite loop but due to an access for more than 20.000 entries the running time was very long. And due to the ORM layer this time was even extended to exceed several hours. I'm working on a small redesign of the database to optimize this issue.
Thanks guys for the support.

[Hive]I got "ArrayIndexOutOfBoundsException" while I query the hive database

I always get "ArrayIndexOutOfBoundsException" while I query the hive base(both hive-0.11.0 and hive-0.12.0), but sometimes not. Here is the error
java.lang.RuntimeException: Hive Runtime Error while closing operators: java.lang.ArrayIndexOutOfBoundsException: 0
at org.apache.hadoop.hive.ql.exec.mr.ExecReducer.close(ExecReducer.java:313)
at org.apache.hadoop.io.IOUtils.cleanup(IOUtils.java:232)
at org.apache.hadoop.mapred.ReduceTask.runOldReducer(ReduceTask.java:539)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:421)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.ArrayIndexOutOfBoundsException: 0
at org.apache.hadoop.hive.ql.exec.persistence.RowContainer.first(RowContainer.java:231)
at org.apache.hadoop.hive.ql.exec.persistence.RowContainer.first(RowContainer.java:74)
at org.apache.hadoop.hive.ql.exec.CommonJoinOperator.genUniqueJoinObject(CommonJoinOperator.java:645)
at org.apache.hadoop.hive.ql.exec.CommonJoinOperator.checkAndGenObject(CommonJoinOperator.java:758)
at org.apache.hadoop.hive.ql.exec.JoinOperator.endGroup(JoinOperator.java:257)
at org.apache.hadoop.hive.ql.exec.mr.ExecReducer.close(ExecReducer.java:298)
... 8 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at org.apache.hadoop.hive.ql.exec.persistence.RowContainer.first(RowContainer.java:220)
... 13 more
Could someone help me?
Update my code:
Select distinct jabberUseragent.gameID,agentPlayInfo.gameLabel,jabberUseragent.userAgent,CONCAT(CONCAT(CONCAT(triggerUsageStart.generateDate,' '),triggerUsageStart.timezone),CONCAT(' ',triggerUsageStart.generateTime)) as generateDate,(unix_timestamp(CONCAT(CONCAT(triggerUsageStop.generateDate,' '),triggerUsageStop.generateTime)) - unix_timestamp(CONCAT(CONCAT(triggerUsageStart.generateDate,' '),triggerUsageStart.generateTime))) from
(Select gameSession,gameID,userAgent from(Select distinct regexp_extract(t.payload,'playRequestId:(.*), playRequest',1) as gameSession,regexp_extract(t.payload,'gameId:(.*), userAgent:',1) as gameID,regexp_extract(t.payload,', userAgent:(.*), agentLocation',1) as userAgent,payload from (select * from ${hiveconf:DATA_BASE} p where p.dt >= '${hiveconf:LOW_DATE}' and p.dt <= '${hiveconf:UPPER_DATE}') t where CONCAT(t.generatedate,t.generatetime) >= CONCAT('${hiveconf:LOW_DATE}','${hiveconf:LOW_TIME}') and CONCAT(t.generatedate,t.generatetime) <= CONCAT('${hiveconf:UPPER_DATE}','${hiveconf:UPPER_TIME}'))jabberUseragent where jabberUseragent.gameSession!='' and jabberUseragent.userAgent!='') jabberUseragent
join
(Select gameID,gameLabel from(Select distinct regexp_extract(t.payload,'gameId=(.*),gameLabel=.*,configFilePath',1) as gameID,regexp_extract(t.payload,'gameId=.*,gameLabel=(.*),configFilePath',1) as gameLabel,payload from (select * from ${hiveconf:DATA_BASE} p where p.dt >= '${hiveconf:LOW_DATE}' and p.dt <= '${hiveconf:UPPER_DATE}') t where CONCAT(t.generatedate,t.generatetime) >= CONCAT('${hiveconf:LOW_DATE}','${hiveconf:LOW_TIME}') and CONCAT(t.generatedate,t.generatetime) <= CONCAT('${hiveconf:UPPER_DATE}','${hiveconf:UPPER_TIME}'))agentPlayInfo where agentPlayInfo.gameID!='' and agentPlayInfo.gameLabel!='') agentPlayInfo
join
(Select gameSession,generateDate,generateTime,timezone,payload from(Select distinct regexp_extract(t.payload,'GAME_SESSION=.*((.{8})-(.{4})-(.{4})-(.{4})-(.{12}))\" USAGE=\"([\\w\\-\\(\\)\\.]*,){41}9.*\"',1) as gameSession,generateDate,generateTime,timezone,payload from (select * from ${hiveconf:DATA_BASE} p where p.dt >= '${hiveconf:LOW_DATE}' and p.dt <= '${hiveconf:UPPER_DATE}') t where t.payload like '%[e] usage_record%' and CONCAT(t.generatedate,t.generatetime) <= CONCAT('${hiveconf:UPPER_DATE}','${hiveconf:UPPER_TIME}') and CONCAT(t.generatedate,t.generatetime) >= CONCAT('${hiveconf:LOW_DATE}','${hiveconf:LOW_TIME}'))triggerStart where triggerStart.gameSession!='')triggerUsageStart
join
(Select gameSession,generateDate,generateTime,timezone,payload from(Select distinct regexp_extract(t.payload,'GAME_SESSION=.*((.{8})-(.{4})-(.{4})-(.{4})-(.{12}))\" USAGE=\"([\\w\\-\\(\\)\\.]*,){41}[1-5].*\"',1) as gameSession,generateDate,generateTime,timezone,payload from (select * from ${hiveconf:DATA_BASE} p where p.dt >= '${hiveconf:LOW_DATE}' and p.dt <= '${hiveconf:UPPER_DATE}') t where t.payload like '%[e] usage_record%' and CONCAT(t.generatedate,t.generatetime) <= CONCAT('${hiveconf:UPPER_DATE}','${hiveconf:UPPER_TIME}') and CONCAT(t.generatedate,t.generatetime) >= CONCAT('${hiveconf:LOW_DATE}','${hiveconf:LOW_TIME}'))triggerStop where triggerStop.gameSession!='')triggerUsageStop
on (jabberUseragent.gameSession = triggerUsageStart.gameSession and triggerUsageStart.gameSession = triggerUsageStop.gameSession and jabberUseragent.gameID = agentPlayInfo.gameID) order by generateDate
Sorry, I can't share my samples.
By the way, I've also got this exception before I got "ArrayIndexOutOfBoundException"
javax.jdo.JDODataStoreException: Error executing SQL query "select PARTITIONS.PART_ID from PARTITIONS inner join TBLS on PARTITIONS.TBL_ID = TBLS.TBL_ID inner join DBS on TBLS.DB_ID = DBS.DB_ID where TBLS.TBL_NAME = ? and DBS.NAME = ? and PARTITIONS.PART_NAME in (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)".
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:451)
at org.datanucleus.api.jdo.JDOQuery.executeWithArray(JDOQuery.java:321)
at org.apache.hadoop.hive.metastore.MetaStoreDirectSql.getPartitionsViaSqlFilterInternal(MetaStoreDirectSql.java:181)
at org.apache.hadoop.hive.metastore.MetaStoreDirectSql.getPartitionsViaSqlFilter(MetaStoreDirectSql.java:82)
at org.apache.hadoop.hive.metastore.ObjectStore.getPartitionsByNamesInternal(ObjectStore.java:1717)
at org.apache.hadoop.hive.metastore.ObjectStore.getPartitionsByNames(ObjectStore.java:1700)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)......
NestedThrowablesStackTrace:
org.postgresql.util.PSQLException: ERROR: relation "partitions" does not exist
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1591)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1340)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:471)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:373)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:258)......
Based on the information provided, only this can be a sensible solution to your problem.
I have put the method definition for reference. Please go through it to understand
If you run down the source code closely, there are two areas / possibilities where ArrayIndexOutOfBoundException can be thrown.
Accessing the array values of input splits from Configuration
Reading the Row from currentReadBlock array (this is mostly not the case for the exception since it's size is greater than 0)
Please check your set of input files for job because InputFormat#split() method returns an array of InputSplit type. Each InputSplit is then assigned to an individual Mapper for processing. Mostly, the exception occurs while accessing this InputSplit[] array.

Categories

Resources