JBoss 缓存配置
我正在使用扩展持久性上下文(在 SFSB 注入 Entitymanager),并另外设置了 @TransactionManagement(value=TransactionManagementType.BEAN)
以使 SFSB 能够完全控制 UserTransaction
。
事务在客户端进行控制,我在客户端开始查找包含对实体 bean 的引用的 SFSB。
SymbolischeWerte sbw = (SymbolischeWerte)symbolischeWerteHome.findByPrimaryKey(BigDecimal.valueOf(24704578762l));
System.out.println(symbolischeWerteHome.getSEQ_ID() + "\t\t" + symbolischeWerteHome.getName());
symbolischeWerteHome.beginTransaction();
symbolischeWerteHome.setName(symbolischeWerteHome.getName().concat("A"));
symbolischeWerteHome.commitTransaction();
到目前为止有效!
启用 JBoss Cache 和多个客户端后,只有第一个客户端会导致数据库选择。其他人从缓存中获取实体。
完美的!
问题:
2个客户端(CLIENTA、CLIENTB)同时查找具有相同主键的实体,当CLIENTA运行程序时,CLIENTB在findByPrimaryKey后手动停止。 当 CLIENTA 完成时(值已成功保留),CLIENTB 的系统会显示已修改并存储到数据库中的旧值。
所以我正在失去 CLIENTA 的价值观!
这是 JBoss 缓存配置问题还是我的系统设计的普遍问题?
实体的缓存配置:
@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, region="com.culturall.pension.system.SymbolischeWerteEntity")
在 persistence.xml 中缓存配置
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory"/>
<property name="hibernate.cache.region.jbc2.cachefactory" value="java:CacheManager"/>
<property name="hibernate.cache.region.jbc2.cfg.entity" value="mvcc-entity"/>
<property name="hibernate.cache.region.jbc2.cfg.query" value="local-query"/>
谢谢您的任何建议!
I'm using an extended persistence context (injected Entitymanager at SFSB) and have additionally set @TransactionManagement(value=TransactionManagementType.BEAN)
for the SFSB to have full control over the UserTransaction
.
The Transaction is controlled on client side where I start a lookup for the SFSBs containing a reference to the entity beans.
SymbolischeWerte sbw = (SymbolischeWerte)symbolischeWerteHome.findByPrimaryKey(BigDecimal.valueOf(24704578762l));
System.out.println(symbolischeWerteHome.getSEQ_ID() + "\t\t" + symbolischeWerteHome.getName());
symbolischeWerteHome.beginTransaction();
symbolischeWerteHome.setName(symbolischeWerteHome.getName().concat("A"));
symbolischeWerteHome.commitTransaction();
that works so far!
After enabling JBoss Cache and multiple clients, only the first client causes a database select. The others get the entity from cache.
perfect!
The problem:
2 clients (CLIENTA, CLIENTB) concurrently looks up for an entity with the same primary key, while CLIENTA runs through the program, CLIENTB is manually halt after findByPrimaryKey.
When CLIENTA has finished (value is successfully persisted) CLIENTB's system out shows the old value which is modified and stored into database too.
So I'm loosing CLIENTA's values!!
Is this a JBoss Cache configuration problem or is this a general problem of my systems design?
Cache config for entity:
@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, region="com.culturall.pension.system.SymbolischeWerteEntity")
Cache config in persistence.xml
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory"/>
<property name="hibernate.cache.region.jbc2.cachefactory" value="java:CacheManager"/>
<property name="hibernate.cache.region.jbc2.cfg.entity" value="mvcc-entity"/>
<property name="hibernate.cache.region.jbc2.cfg.query" value="local-query"/>
Thx for ANY advice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我没看错的话,您将缓存配置为事务性的。根据定义,这意味着不同交易中的客户端会看到不同版本的数据;如果数据在其他事务中被修改,您需要显式刷新数据库中的数据(从而放弃您的更改)才能看到这些更改。
If I read you right, you configured the cache to be transactional. This by definition means clients in different transactions see different versions of data; if the data was modified in other transaction, you need to refresh the data from DB explicitely (thus discarding your changes) to see those changes.