开发者

Hibernate Caching Negative Hits

I have two tables from two different departments:

Customer

ID

County

State

Na开发者_如何学JAVAme, Age, etc.

Billing Rate (composite ID of County/State)

County

State

Price

In Hibernate, I have defined a @ManyToOne relationship on a composite foreign key (county/state). I followed this: Hibernate Annotations

Well, Every Customer has a county/state, but not every county-state pair is represented in the billing table. When I load some of the Customer entities, I get an exception of EntityNotFoundException for the relationship. Based on my reading here (same problem as me): JBoss Forums It looks like every relationship NEEDS to be there, although you can slap on a @NotFound(action=IGNORE) tag. Well, I did that too and it works without error, but I'm still having a problem. Hibernate does not cache the negative-hits, so if a county/state pair is NOT found, the exception is ignored, but the knowledge of that "lack of data" is not cached, so it re-loads the relationship on demand, every time. So, when I do a left join fetch on the relationship, it effectively does nothing for me. Also, a batch-fetch does nothing, I have to load them one at a time, and I'm talking about thousands of entities.

What can I do to resolve this? Is the DB designed wrong??? Thanks!


Unfortunately, Hibernate second-level (are you assuming it?) cache doesn't support caching of objects with composite identifiers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜