[RESOLVIDO]Consulta Hibernate com parametro

:shock: Estou tendo dificuldade em pegar o resultado de uma consulta com parâmetros no Hibernate a mesma consuta sem parâmetros pegando todos os dados da tabela está funcionando corretamente.

Agradeco a quem puder me ajudar.

[code] public ArrayList getLista(String documento) throws SQLException{

 Session session = HibernateUtil.getSessionFactory().openSession();

Transaction tx = session.beginTransaction();



List <Socio>socio=(List<Socio> )session.createQuery("FROM Socio AS socio WHERE socio.cpf  =: :?:  :?:  inf").setParameter("inf",documento).list();

tx.commit();
session.close();

Exception in thread “AWT-EventQueue-0” org.hibernate.QueryException: Space is not allowed after parameter prefix ‘:’ 'FROM Socio AS socio WHERE socio.cpf =: documento’
at org.hibernate.engine.query.ParameterParser.parse(ParameterParser.java:68)
at org.hibernate.engine.query.ParamLocationRecognizer.parseLocations(ParamLocationRecognizer.java:51)
at org.hibernate.engine.query.HQLQueryPlan.buildParameterMetadata(HQLQueryPlan.java:266)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:97)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at controle.dao.socio.cadastro.SocioDao.getLista(SocioDao.java:206)
at controle.gui.cadastro.JDSelecionaSocio.pesquisaSocio(JDSelecionaSocio.java:188)
at controle.gui.cadastro.JDSelecionaSocio.access$0(JDSelecionaSocio.java:185)
at controle.gui.cadastro.JDSelecionaSocio$4.actionPerformed(JDSelecionaSocio.java:117)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
at java.awt.Component.processMouseEvent(Component.java:6136)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:5901)
at java.awt.Container.processEvent(Container.java:2105)
at java.awt.Component.dispatchEventImpl(Component.java:4497)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Component.dispatchEvent(Component.java:4323)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4125)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4055)
at java.awt.Container.dispatchEventImpl(Container.java:2149)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4323)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:649)
at java.awt.EventQueue.access$000(EventQueue.java:96)
at java.awt.EventQueue$1.run(EventQueue.java:608)
at java.awt.EventQueue$1.run(EventQueue.java:606)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$2.run(EventQueue.java:622)
at java.awt.EventQueue$2.run(EventQueue.java:620)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:619)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)

[/code]

o erro tá aqui “=: :?: :?:” o que você quiz passar com isso?
não seria só :inf ?

este link vai te ajudar muito.
http://www.mkyong.com/hibernate/hibernate-parameter-binding-examples/

Não é mais fácil usar os Restrictions do Criteria para tal?Criteria criteria = session.createCriteria(); criteria.add(Restrictions.eq("cpf", "seuParametro")); List<Socio> socioList = criteria.list();

como o nosso amigo klerdamasco disse acho que o erro está nos parametros também.
se for o que entendi o que está querendo fazer ficaria como o codigo abaixo.

 List <Socio>socio=(List<Socio> )session.createQuery("FROM Socio AS socio WHERE socio.cpf  =:inf").setParameter("inf",documento).list();

Vlw

Funcionou corretamente.