Hi. EntityManager.createQuery() creates a query using the Java Persistence Query Language, rather than an actual SQL query. For a straight SQL query, I think you want to use EntityManager.createNativeQuery().
...Of course, as long as you're using JPA already, you might be better off just doing your update using that API, rather than doing a direct SQL call. But I guess it depends on what exactly you're doing. -allen On Mon, Aug 31, 2009, 11:54, Fabio Fonseca <[email protected]> wrote >Hello All, > >After some hours trying to get it to work, I'm asking for help. > >What I want to do is to update a database record accordingly to a SELECT >result from a SQL clause. I've typed this clause in the MySQL's client and >it works ok. The data row is updated after a return from the SELECT >statement. > >So I tried to use this SELECT/UPDATE clause inside my app code, but I don't >know what I'm doing wrong. Instead of the persisted COLUMNs from the DB, I'm >using the name of the classes. But of no avail. > >Stripersist.getEntityManager() > .createQuery("update location INNER JOIN (select >location.localidade_id, count(*) as n_count from >"+getEntityClass().getName()+" as inv where inv.status_ocorrencia='DOWN' >group by localidade_id) as myJoint set location.num_loc_down = >myJoint.n_count where location.id = >myJoint.localidade_id").getResultList(); > > >the error from the log file is the following: > >Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: >INNER near line 1, column 17 [update location INNER JOIN select >location.localidade_id, count(*) as n_count from buzzlabs.model.Inventory as >inv where inv.status_ocorrencia='DOWN' group bylocalidade_id as myJoint set >location.num_loc_down = myJoint.n_count where location.id = >myJoint.localidade_id] > > >thank you very much for your attention! >Fabio > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Stripes-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/stripes-users
