wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes parameter not set! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "parameter not set!" Watch "parameter not set!" New topic
Author

parameter not set!

Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
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

Joined: Feb 14, 2006
Posts: 121
Sorted it myself.

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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Feb 14, 2006
Posts: 121

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
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Feb 05, 2009
Posts: 3
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

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Steven Swor
Greenhorn

Joined: Feb 05, 2009
Posts: 3
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

Joined: Feb 05, 2009
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parameter not set!
 
Similar Threads
it is giving fatal exception
one to many bidirectional error driving me mad
Many to Many Relation Error Driving Me Mad
SQLQuery not working
@ManyToOne & @JoinColumn