A Hibernate Issue

Jesus M. Rodriguez jmrodri at gmail.com
Sat Feb 27 23:41:35 UTC 2010


On Fri, Feb 26, 2010 at 1:47 PM, Devan Goodwin <dgoodwin at rm-rf.ca> wrote:
> Hey guys, BK found an issue with hibernate, essentially he was
> starting Candlepin in tomcat, loading a cert, which creates
> entitlement pools each affiliated with an owner. When he then went to
> his new API call for owner/{id}/entitlementpool to get the list, it
> would come back empty, even though the pools were in the db and
> correctly pointing to the owner. Restart tomcat, hit the same URL, and
> now the entitlement pools would appear.

Is there a way to check to make sure the data is in the db after the original
request (before the restart)?


>
> The issue was this:
>
> diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/SpacewalkCertificateCurator.java
> b/proxy/src/main/java/org/fedoraproject/candlepin/model/SpacewalkCertificateCurator.java
> index 3d618e8..c24e93f 100644
> --- a/proxy/src/main/java/org/fedoraproject/candlepin/model/SpacewalkCertificateCurator.java
> +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/SpacewalkCertificateCurator.java
> @@ -134,6 +134,7 @@ public class SpacewalkCertificateCurator {
>         ep.setStartDate(start);
>         ep.setEndDate(end);
>         ep.setCurrentMembers(0);
> +        owner.addEntitlementPool(ep);
>         entitlementPoolCurator.create(ep);
>     }
>
> I know we've seen this issue before both in CP and back in Spacewalk,
> and pretty sure we've had some conversations about it at times too, I
> thought the outcome of that was to do the above.
>
> The call to create the entitlement pool does end up calling flush, so
> I don't think this is the issue, but Hibernate still keeps the owner
> object laying around.

So you had to explicitly add the ep to the owner because Hibernate
isn't making the SQL query to reload the owner after the creation of
the ep. That totally sounds like caching.  Is it the same session or
a new hibernate session?

I know the problem in spacewalk is we cache some items and when
we update the db we never refresh them (usually they are static
so a restart reloads them all). For things that change often we didn't
cache them.

>
> When a new call comes in to our REST API, should this be using a
> cached Owner? I kinda thought it would clear the cache on each
> request. (if not is that something we could/should do?)

Back to Spacewalk, the SessionFilter handles all of the commits
and opening new hibernate sessions and txns. I thought we went to
a per request txn model in candlepin as well. So in theory, a new request
should be an entirely new db request too.  /me will ponder this a bit more.

jesus



More information about the candlepin mailing list