Steven Swor

+ Follow
since Feb 05, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Steven Swor

Nevermind. I found the problem and fixed it. I misunderstood how worked. is kind of like Restrictions.eq(), except that it works with a list of values instead of a single one. For example, if I wanted to get a list of ProgramUsers from a known set of IDs, I could use the following method:

This method will return a list containing 5 users (assuming all 5 idents appear in the ProgramUser table). This has its uses, but it won't do what I need it to do.

What I really needed was an additional Criterion on each user's "groups" collection, to make sure that the group appeared in that collection. Here's the corrected method:

And here's the query generated by Hibernate. Aside from the table/column aliases, it's pretty much what I would have done if I'd written it in pure SQL.
Thanks for the quick response, Paul

My project uses Hibernate 3 and MySQL 5 with the InnoDB engine. (For what it's worth, I'm also using Spring, XFire, and Tomcat, but I doubt my problem is related to any of these)

I have the following classes in my domain model:

As you can see, each user maintains a collection of the groups to which it belongs. I also want to be able to get a listing of all users who belong to a particular group (while avoiding circular references), so I have the following method in my

The above method looks like it should give me what I want (I'll admit that I'm still fairly new to both Hibernate and JPA), but when I try to run it, it throws this exception:

org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.loader.Loader.doList(
at org.hibernate.loader.Loader.listIgnoreQueryCache(
at org.hibernate.loader.Loader.list(
at org.hibernate.loader.criteria.CriteriaLoader.list(
at org.hibernate.impl.SessionImpl.list(
at org.hibernate.impl.CriteriaImpl.list(
at com.summit.datalinc.auth.common.HibernateAuthDAO$30.doInTransaction(
at com.summit.datalinc.auth.common.HibernateAuthDAO.getUsersForGroup(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(
at $Proxy12.getUsersForGroup(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.codehaus.xfire.service.invoker.AbstractInvoker.invoke(
at org.codehaus.xfire.service.binding.ServiceInvocationHandler.sendMessage(
at org.codehaus.xfire.service.binding.ServiceInvocationHandler$
at org.codehaus.xfire.service.binding.ServiceInvocationHandler.execute(
at org.codehaus.xfire.service.binding.ServiceInvocationHandler.invoke(
at org.codehaus.xfire.handler.HandlerPipeline.invoke(
at org.codehaus.xfire.transport.DefaultEndpoint.onReceive(
at org.codehaus.xfire.transport.AbstractChannel.receive(
at org.codehaus.xfire.transport.http.XFireServletController.invoke(
at org.codehaus.xfire.transport.http.XFireServletController.doService(
at org.codehaus.xfire.spring.remoting.XFireServletControllerAdapter.handleRequest(
at org.codehaus.xfire.spring.remoting.XFireExporter.handleRequest(
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(
at org.springframework.web.servlet.DispatcherServlet.doDispatch(
at org.springframework.web.servlet.DispatcherServlet.doService(
at org.springframework.web.servlet.FrameworkServlet.processRequest(
at org.springframework.web.servlet.FrameworkServlet.doPost(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
Caused by: java.sql.SQLException: No value specified for parameter 1
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.PreparedStatement.fillSendPacket(
at com.mysql.jdbc.PreparedStatement.fillSendPacket(
at com.mysql.jdbc.PreparedStatement.executeQuery(
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(
at org.hibernate.jdbc.AbstractBatcher.getResultSet(
at org.hibernate.loader.Loader.getResultSet(
at org.hibernate.loader.Loader.doQuery(
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(
at org.hibernate.loader.Loader.doList(
... 50 more

With show_sql and format_sql turned on, I see that the exception was thrown when Hibernate attempted to run the following query:

For some reason, the parameter isn't being set in the prepared statement, but I'm not sure why. I can run this query in MySQL Query Browser and get results. I figure I'm doing something wrong with my "" part, but I'm baffled as to what it could be.

Alana Sparx wrote:Sorted it myself.

I'd tell you, but owing to your reticence, you don't deserve to know.

I'm having the same problem with the parameter not being set. I've tried everything I can think of to make it work, and I'm all out of ideas. Can you please post how you fixed this?