Re: [hibernate-users] Stale query cache by column
by Luiz Fernando O. C. Real
Hi, everyone,
I've found a way, although I'm not sure it's the best way to do it.
I implemented a CustomEntityPersister, extending the
SingleTableEntityPersister. In this new class, I overwrote the protected
update method, inherited from AbstractEntityPersister, and in the new
implementation I verify which fields are dirty and, if they match the ones I
want to be stale-tolerant, I set a flag so that later, when Hibernate
queries which spaces are modified by the persister (via getPropertySpaces),
I return an empty array.
Any comments?
Thanks for the help.
--
Luiz F. O. Corte Real
Vida Geek
http://vidageek.net
Caelum | Ensino e Inovação
http://www.caelum.com.br
On Thu, Apr 7, 2011 at 9:44 AM, Luiz Fernando O. C. Real <
luiz.real(a)caelum.com.br> wrote:
> Hi Joe,
>
> Is it really possible? If so, how can I do it?
>
> We are trying to use the QueryCache more effectively, that's why we are
> thinking of hacking the cache system. There's this User model with the
> lastLogin attribute that is changed every time the user logs into the
> system. And then, every time an user logs in, all the cached queries related
> to the User model are invalidated. And most of the cached queries are
> related to this model.
>
> Any other idea?
>
>
> Thanks
>
> --
> Luiz F. O. Corte Real
>
> Vida Geek
> http://vidageek.net
>
> Caelum | Ensino e Inovação
> http://www.caelum.com.br
>
>
> On Mon, Apr 4, 2011 at 4:25 PM, Haswell, Joe <josiah.d.haswell(a)hp.com>wrote:
>
>> Hi Luiz,
>>
>>
>>
>> Sorry, I didn’t read back through the thread in its entirety before
>> responding. A cached result is by definition invalid after the backing
>> store has been modified in any way. It is possible to override this
>> behavior, but is that either necessary or desirable? If this is a
>> performance consideration, you should assess whether the default performance
>> is acceptable before trying to improve it. I think selectively disabling
>> cache-invalidation is always going to look a bit hacky because it
>> contravenes the cache-store contract.
>>
>>
>>
>> Thanks,
>>
>>
>>
>> Joe H. | HP Software
>>
>>
>>
>> *From:* sr.saude(a)gmail.com [mailto:sr.saude@gmail.com] *On Behalf Of *Luiz
>> Fernando O. C. Real
>> *Sent:* Monday, April 04, 2011 1:01 PM
>> *To:* Haswell, Joe
>>
>> *Subject:* Re: [hibernate-users] Stale query cache by column
>>
>>
>>
>> Hi, Joe
>>
>> Sorry, I think I didn't make myself clear. I understand that I can listen
>> for the update to a particular table, but the event, AFAIK, is triggered
>> after the cache invalidation, and I would like to not invalidate the cache
>> for a specific update.
>>
>> --
>> Luiz F. O. Corte Real
>>
>> Vida Geek
>> http://vidageek.net
>>
>> Caelum | Ensino e Inovação
>> http://www.caelum.com.br
>>
>> On Mon, Apr 4, 2011 at 3:50 PM, Haswell, Joe <josiah.d.haswell(a)hp.com>
>> wrote:
>>
>> I’m not entirely sure I understand what the problem is. You could
>> certainly create your own event-listener that listened for an update to that
>> particular table. From my understanding of the problem, the cache becomes
>> invalid immediately after an update occurs, which is when your
>> event-listener would be triggered. This seems to me to be the correct time
>> to invalidate your cache. Caches can be invalidated programmatically by
>> Hibernate (which is what I suspect you’re seeing), or you can invalidate
>> them manually. If Hibernate’s default cache-invalidation is unsuitable, can
>> you override it with appropriate semantics?
>>
>>
>>
>> Joe H. | HP Software
>>
>> *From:* hibernate-users-bounces(a)lists.jboss.org [mailto:
>> hibernate-users-bounces(a)lists.jboss.org] *On Behalf Of *Luiz Fernando O.
>> C. Real
>> *Sent:* Monday, April 04, 2011 12:39 PM
>> *To:* hibernate-users
>> *Subject:* Re: [hibernate-users] Stale query cache by column
>>
>>
>>
>> Hi, again
>>
>> Thanks for the reply, Joe. I've checked out the event system and could not
>> find anything helpful. It seems that the generated events are only fired
>> after the cache is invalidated.
>>
>> I've found a way to do this implementing a QueryCache, but it's not the
>> most elegant solution. I verify the query to be retrieved from the cache via
>> the toString() method in the QueryKey object. If the SQL matches the one I'm
>> trying to turn stale cache tolerant, I ignore the timestamp.
>>
>> Is there a better way to do this, to look at the query being passed?
>> Wouldn't it be nice to have a getter for it in the QueryKey class?
>>
>> Thanks
>>
>> --
>> Luiz F. O. Corte Real
>>
>> Vida Geek
>> http://vidageek.net
>>
>> Caelum | Ensino e Inovação
>> http://www.caelum.com.br
>>
>> On Thu, Mar 24, 2011 at 12:16 PM, Haswell, Joe <josiah.d.haswell(a)hp.com>
>> wrote:
>>
>> I’d check out the event system. If a particular event invalidates your
>> cache, just clear it or the region of it that’s invalid.
>>
>>
>>
>> Joe H. | HP Software
>>
>>
>>
>> *From:* hibernate-users-bounces(a)lists.jboss.org [mailto:
>> hibernate-users-bounces(a)lists.jboss.org] *On Behalf Of *Luiz Fernando O.
>> C. Real
>> *Sent:* Thursday, March 24, 2011 9:06 AM
>> *To:* hibernate-users
>> *Subject:* [hibernate-users] Stale query cache by column
>>
>>
>>
>> Hi,
>>
>> I'm trying to implement a custom QueryCache that, like the example in
>> http://community.jboss.org/wiki/QueryCache, does not invalidate some
>> existing register is updated in a specific table. However, unlike the
>> example, I'd like to do that by analyzing which columns were changed in an
>> update.
>>
>> More precisely, I have an User table, which has a lastLogin column. I'd
>> like to keep the QueryCache valid when I update the lastLogin of an User.
>>
>> I haven't found any way to do that yet. Is that possible?
>>
>> Thanks in advance.
>>
>> --
>> Luiz F. O. Corte Real
>>
>> Vida Geek
>> http://vidageek.net
>>
>> Caelum Objects
>> http://www.caelumobjects.com
>>
>>
>>
>>
>>
>
>
13 years, 7 months
Hibernate in Tomcat
by הילה
Hey guys,
I tried to explore a bit the possibility of hibernate in tomcat, but some
things aren't that clear for me.
Before hitting the specific questions, please explain what is hibernate in
Tomcat, when do we want to use it, how do I use it specifically with the
JDBC connection pool (instead of the default DBCP connection pool), and if
misconfiguration of the hibernate can cause disconnections of users on the
application (that uses tomcat).
Now for 2 specific questions, if I may :]
1. in this article, its states that hibernate can be used for managing the
JDBC connection pool, but the strings are for c3p0 pool-
http://community.jboss.org/wiki/UsingHibernatewithTomcat
why is that?
can I use both c3p0 settings with Datasource pool (JNDI?) ?
2. Do I have to use hibernate.properties file, or can I rename it to
x.properties and still use the content of the hibernate settings?
Errors in my application when there are disconnections (between client and
app server, that caused by disconnections between app server and DB), that
leads me to think there's a problem with the hibernate settings:
* ERROR, hibernate.transaction.
JDBCTransaction JDBC begin failed javasql.SQLException: Invalid state, the
Connection object is closed.
* org.hibernate.util.JDBCExceptionReporter , Timeout: Pool empty. Unable to
fetch a connection in 10 seconds, none available[0 in use]
* WARN, hibernate.util.JDBCExceptionReporter SQL Error: 0, SQLState: 08S01
ERROR, hibernate.util.JDBCExceptionReporter I/O Error: DB server closed
connection.
ERROR, error processing request: exception.*appname*Error:
.hibernate.exception.JDBCConnectionException: Cannot open connection
Does my hunch is correct, and I need to change hibernate settings for the
disconnections to stop from occuring? or is it something else?
Thanks
Hila
13 years, 7 months
Re: [hibernate-users] Stale query cache by column
by Luiz Fernando O. C. Real
Hi, again
Thanks for the reply, Joe. I've checked out the event system and could not
find anything helpful. It seems that the generated events are only fired
after the cache is invalidated.
I've found a way to do this implementing a QueryCache, but it's not the most
elegant solution. I verify the query to be retrieved from the cache via the
toString() method in the QueryKey object. If the SQL matches the one I'm
trying to turn stale cache tolerant, I ignore the timestamp.
Is there a better way to do this, to look at the query being passed?
Wouldn't it be nice to have a getter for it in the QueryKey class?
Thanks
--
Luiz F. O. Corte Real
Vida Geek
http://vidageek.net
Caelum | Ensino e Inovação
http://www.caelum.com.br
On Thu, Mar 24, 2011 at 12:16 PM, Haswell, Joe <josiah.d.haswell(a)hp.com>wrote:
> I’d check out the event system. If a particular event invalidates your
> cache, just clear it or the region of it that’s invalid.
>
>
>
> Joe H. | HP Software
>
>
>
> *From:* hibernate-users-bounces(a)lists.jboss.org [mailto:
> hibernate-users-bounces(a)lists.jboss.org] *On Behalf Of *Luiz Fernando O.
> C. Real
> *Sent:* Thursday, March 24, 2011 9:06 AM
> *To:* hibernate-users
> *Subject:* [hibernate-users] Stale query cache by column
>
>
>
> Hi,
>
> I'm trying to implement a custom QueryCache that, like the example in
> http://community.jboss.org/wiki/QueryCache, does not invalidate some
> existing register is updated in a specific table. However, unlike the
> example, I'd like to do that by analyzing which columns were changed in an
> update.
>
> More precisely, I have an User table, which has a lastLogin column. I'd
> like to keep the QueryCache valid when I update the lastLogin of an User.
>
> I haven't found any way to do that yet. Is that possible?
>
> Thanks in advance.
>
> --
> Luiz F. O. Corte Real
>
> Vida Geek
> http://vidageek.net
>
> Caelum Objects
> http://www.caelumobjects.com
>
13 years, 7 months