• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

parameter not set!

 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate is driving me crazy.

Model class (informationDisplay.java):



daoHibernate class


if I comment out the line infoCriteria.add(in(PROP_GROUP, groups));, everything works as expected. Leaving it in throws it all over the place:
1) sql error stating parameter #2 has not been set - eh?
2) the id of the Group object contained in the group set looks like it is being used to search the id of Information_Display - it should be set to the GROUP_ID of GROUP_INFORMATION_DISPLAY. I thought Hibernate took care of this.

Can anyone help. I've been battering my head against this wall all afternoon, in which time I could have JDBC'd half the bloody universe!!!
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorted it myself.

I'd tell you, but owing to your reticence, you don't deserve to know.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am missing something here in

infoCriteria.add(in(PROP_GROUP, groups));

where is the "in" method? Is that a method you have implemented, or something that is coming from a static import? And if you implemented it what does it look like.

Thanks

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alana Sparx:
Sorted it myself.

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



Alana, Sorry, I had my response on my machine for a couple hours, but got called into a meeting. Also the more detailed the question the more responses you get, I think what happened here was that people weren't quite sure what you were asking. There was some missing information.

Regardless of getting answers or not, I will take your "you don't deserve to know." as a joke rather than breaking one of the only two rules we have at JavaRanch, be nice.

Mark
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am missing something here in

infoCriteria.add(in(PROP_GROUP, groups));

where is the "in" method? Is that a method you have implemented, or something that is coming from a static import? And if you implemented it what does it look like.


Yes, it was a static import from the Restrictions class.

I could have implemented it myself, but it would have been awful....
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alana Sparx:

I am missing something here in

infoCriteria.add(in(PROP_GROUP, groups));

where is the "in" method? Is that a method you have implemented, or something that is coming from a static import? And if you implemented it what does it look like.


Yes, it was a static import from the Restrictions class.

I could have implemented it myself, but it would have been awful....



OK, I assume that either the collection wasn't the right type, or something along those lines.

Mark
 
Steven Swor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steven Swor wrote:

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?



I'm not sure Alana will be around to answer you more than a year an a half after this question was posted!

When you say I have the same problem are you doing the same thing? Or are you doing something different and getting a simmilar message? Can you post your code and any error message/stack trace you have?
 
Steven Swor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
UserGroup.java

ProgramUser.java

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 HibernateAuthDAO.java:

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(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2216)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.summit.datalinc.auth.common.HibernateAuthDAO$30.doInTransaction(HibernateAuthDAO.java:663)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
at com.summit.datalinc.auth.common.HibernateAuthDAO.getUsersForGroup(HibernateAuthDAO.java:655)
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:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
at $Proxy12.getUsersForGroup(Unknown Source)
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:597)
at org.codehaus.xfire.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:59)
at org.codehaus.xfire.service.binding.ServiceInvocationHandler.sendMessage(ServiceInvocationHandler.java:320)
at org.codehaus.xfire.service.binding.ServiceInvocationHandler$1.run(ServiceInvocationHandler.java:86)
at org.codehaus.xfire.service.binding.ServiceInvocationHandler.execute(ServiceInvocationHandler.java:134)
at org.codehaus.xfire.service.binding.ServiceInvocationHandler.invoke(ServiceInvocationHandler.java:109)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:64)
at org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38)
at org.codehaus.xfire.transport.http.XFireServletController.invoke(XFireServletController.java:304)
at org.codehaus.xfire.transport.http.XFireServletController.doService(XFireServletController.java:129)
at org.codehaus.xfire.spring.remoting.XFireServletControllerAdapter.handleRequest(XFireServletControllerAdapter.java:67)
at org.codehaus.xfire.spring.remoting.XFireExporter.handleRequest(XFireExporter.java:48)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:637)
Caused by: java.sql.SQLException: No value specified for parameter 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2176)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2100)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1826)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
... 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 "Restrictions.in()" part, but I'm baffled as to what it could be.
 
Steven Swor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind. I found the problem and fixed it. I misunderstood how Restrictions.in() worked.

Restrictions.in() 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic