Fabio,
I've never tried it but at the bottom of the page I sent the link to it
says you can do an UPDATE with JPQL.
Of course it depends on what you're trying to do but I would probably
load the object I was trying to update and change the object properties
instead of trying to do it through JPQL. That way I could refactor
without having to worry about breaking JPQL update strings.
I try to do as little JPQL as possible. Most of the time I'm using
Hibernate with JPA and will follow Freddy's example from the book to
take advantage of Hibernate's Criteria instead.
Aaron
Fabio Fonseca wrote:
Hi Aaron,
Well, well, still not getting it. I see that JPA will take care of the
objects I'm using at the moment, e.g., after a form submission or a
call to a DAO, but what if I need to update the properties of a second
object (actually the table) based on the results of my query on the
first object? How would I proceed? should I first instantiate the
second object, do a SecondObjectDao.read(), query the 1st object and
then commit the transaction?
thanks for the tip on Quartz, will check it later!
cheers!
Fabio
On Mon, Aug 31, 2009 at 4:50 PM, Aaron Porter <[email protected]
<mailto:[email protected]>> wrote:
Hi Fabio,
With JPA you shouldn't normally have to do any UPDATEs. You just
change your model objects then commit. JPA takes care of figuring
out which objects have been modified and saves the changes to the
database for you.
The string you pass to
Stripersist.getEntityManager().createQuery() is JPQL, not SQL.
http://www.jpox.org/docs/1_2/jpa/jpql.html
Stripes does not have any to schedule threads. A lot of people
seem to be using Quartz to do that.
Aaron
Fabio Fonseca wrote:
Think it would be easier if I explained what I'm trying to
accomplish.
There is the Class with a graph like this
(Parent) (has-a) (has-a)
Inventory -> Location -> geoLocation
after every hour, I need to update a field in the geoLocation
persisted table with information from the Inventory. My first
thought was to run the UPDATE SQL query, merging its results with
the geoLocation table. But now I see that as an Inventory already
holds (indirectly) a geoLocation, I could access and update it
using the Inventory parent class, right?
But I'm still confused about what to write inside the
Stripersist.getEntityManager().createQuery(). What kind of SQL
should it holds? HQL's, MySQL's, JPA? Where could I learn more
about it? I'm going to implement some very specific queries, but
I dunno where to start looking for. I'm confused specially by the
UPDATEs, since I could find none on the Stripes Book code. =) How
you update the fields, freddy?
BTW, does stripes have some option for specifying scheduled
threads? Besides updating this table from time to time, I will
need to generate some graphics from our data, on a hourly basis,
probably.
bye!
Fabio
On Mon, Aug 31, 2009 at 12:54 PM, Fabio Fonseca
<[email protected] <mailto:[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 <http://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 <http://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]
<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/stripes-users
------------------------------------------------------------------------------
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]
<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/stripes-users
------------------------------------------------------------------------
------------------------------------------------------------------------------
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
------------------------------------------------------------------------------
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