Yes, I can run other queries with no problem. Actually what I'm doing is fetching a ROLE from the db, then fetch a GROUP, then I want to add the ROLE to the "set of ROLES" in GROUP <many-to-many>.
Here is the entire method that fetches the GROUP:
Code:
public Group findById(Long id) {
log.debug("In Group findById");
List<Group> list = getHibernateTemplate().getSessionFactory()
.getCurrentSession().createCriteria(Group.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.setFetchMode("roles", FetchMode.JOIN)
.add(Restrictions.eq("groupId", id)).list();
log.debug("after fetch");
Group g = list.get(0);
log.debug("group.roles.size is: " + g.getRoles().size());
return (list.size() > 0) ? list.get(0) : null;
}
This specific piece of code fails in the
.list() method. If I comment out
//.setFetchMode("roles", FetchMode.JOIN) then the .list() method succeeds and the
list.get(0) fails.
Each failure stems from trying to access the set in the <many-to-many>. If I only access the GROUP there is no problem but GROUP.getRoles() fails.
Here is the logging starting from my log statement at the beginning of the method:
Code:
DEBUG - GroupDAOImpl.findById(45) | In Group findById
DEBUG - AbstractBatcher.logOpenPreparedStatement(410) | about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG - SQLStatementLogger.logStatement(111) | select this_.groupId as groupId5_1_, this_.companyId as companyId5_1_, this_.creatorUserId as creatorU3_5_1_, this_.classNameId as classNam4_5_1_, this_.classPK as classPK5_1_, this_.parentGroupId as parentGr6_5_1_, this_.liveGroupId as liveGrou7_5_1_, this_.name as name5_1_, this_.description as descript9_5_1_, this_.type_ as type10_5_1_, this_.typeSettings as typeSet11_5_1_, this_.friendlyURL as friendl12_5_1_, this_.active_ as active13_5_1_, roles2_.groupId as groupId3_, role3_.roleId as roleId3_, role3_.roleId as roleId9_0_, role3_.companyId as companyId9_0_, role3_.classNameId as classNam3_9_0_, role3_.classPK as classPK9_0_, role3_.name as name9_0_, role3_.description as descript6_9_0_, role3_.type_ as type7_9_0_ from flair.Group_ this_ left outer join GroupRole roles2_ on this_.groupId=roles2_.groupId left outer join flair.role_ role3_ on roles2_.roleId=role3_.roleId where this_.groupId=?
Hibernate: select this_.groupId as groupId5_1_, this_.companyId as companyId5_1_, this_.creatorUserId as creatorU3_5_1_, this_.classNameId as classNam4_5_1_, this_.classPK as classPK5_1_, this_.parentGroupId as parentGr6_5_1_, this_.liveGroupId as liveGrou7_5_1_, this_.name as name5_1_, this_.description as descript9_5_1_, this_.type_ as type10_5_1_, this_.typeSettings as typeSet11_5_1_, this_.friendlyURL as friendl12_5_1_, this_.active_ as active13_5_1_, roles2_.groupId as groupId3_, role3_.roleId as roleId3_, role3_.roleId as roleId9_0_, role3_.companyId as companyId9_0_, role3_.classNameId as classNam3_9_0_, role3_.classPK as classPK9_0_, role3_.name as name9_0_, role3_.description as descript6_9_0_, role3_.type_ as type7_9_0_ from flair.Group_ this_ left outer join GroupRole roles2_ on this_.groupId=roles2_.groupId left outer join flair.role_ role3_ on roles2_.roleId=role3_.roleId where this_.groupId=?
DEBUG - AbstractBatcher.logClosePreparedStatement(418) | about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - JDBCExceptionReporter.logExceptions(92) | could not execute query [select this_.groupId as groupId5_1_, this_.companyId as companyId5_1_, this_.creatorUserId as creatorU3_5_1_, this_.classNameId as classNam4_5_1_, this_.classPK as classPK5_1_, this_.parentGroupId as parentGr6_5_1_, this_.liveGroupId as liveGrou7_5_1_, this_.name as name5_1_, this_.description as descript9_5_1_, this_.type_ as type10_5_1_, this_.typeSettings as typeSet11_5_1_, this_.friendlyURL as friendl12_5_1_, this_.active_ as active13_5_1_, roles2_.groupId as groupId3_, role3_.roleId as roleId3_, role3_.roleId as roleId9_0_, role3_.companyId as companyId9_0_, role3_.classNameId as classNam3_9_0_, role3_.classPK as classPK9_0_, role3_.name as name9_0_, role3_.description as descript6_9_0_, role3_.type_ as type7_9_0_ from flair.Group_ this_ left outer join GroupRole roles2_ on this_.groupId=roles2_.groupId left outer join flair.role_ role3_ on roles2_.roleId=role3_.roleId where this_.groupId=?]
java.sql.SQLException: No database selected
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at com.flair.dao.impl.GroupDAOImpl.findById(GroupDAOImpl.java:50)
at com.flair.service.impl.GroupManagerImpl.findById(GroupManagerImpl.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy5.findById(Unknown Source)
at com.flair.dao.RoleTestCase.testGroupRole(RoleTestCase.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
WARN - JDBCExceptionReporter.logExceptions(100) | SQL Error: 1046, SQLState: 3D000
ERROR - JDBCExceptionReporter.logExceptions(101) | No database selected
DEBUG - JDBCTransaction.rollback(186) | rollback
DEBUG - JDBCTransaction.toggleAutoCommit(227) | re-enabling autocommit
DEBUG - JDBCTransaction.rollback(197) | rolled back JDBC Connection
DEBUG - ConnectionManager.afterTransaction(325) | transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
DEBUG - ConnectionManager.closeConnection(464) | releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
DEBUG - ConnectionManager.afterTransaction(325) | transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!