[JBossCache] - Exception thrown when calling remove during after-completion
by rworsnop
JBoss Cache version: 1.4.1.SP2
I have been having some problems using Hibernate with JBoss Cache in optimistic locking mode. During the after-completion phase of the transaction, Hibernate will, in certain circumstances, call TreeCache.remove.
This causes problems because JBoss Cache sees that the transaction is committing. A CacheException is thrown, with a "Must be in a valid transaction" message.
The code below replicates what Hibernate does:
public static void main(String[] args) throws Exception {
| TreeCache tree = new TreeCache();
| tree.setTransactionManagerLookup(new DummyTransactionManagerLookup());
| tree.setCacheMode(TreeCache.LOCAL);
| tree.setNodeLockingScheme("optimistic");
| tree.startService(); // kick start tree cache
| TransactionManager txManager = DummyTransactionManager.getInstance();
|
| try {
| txManager.begin();
| txManager.getTransaction().registerSynchronization(remover(tree));
| tree.put(fqn("custard"), "item", 45);
| txManager.commit();
| }
| catch(Throwable ex) {
| ex.printStackTrace();
| try { txManager.rollback(); } catch(Throwable t) {}
| } finally{
| tree.stopService();
| }
| }
|
| private static Synchronization remover(final TreeCache tree) {
| return new Synchronization(){
|
| public void afterCompletion(int status) {
| try {
| tree.remove(fqn("custard"), option(false));
| } catch (CacheException e) {
| System.err.println("Bad things happened when I tried to remove custard");
| e.printStackTrace();
| }
| }
| public void beforeCompletion() {
| }
|
| };
| }
|
| private static Fqn fqn(String s){
| return Fqn.fromString(s);
| }
|
| private static Option option(boolean failSilently){
| Option option = new Option();
| option.setFailSilently( failSilently );
| option.setDataVersion(new DataVersion(){
|
| public boolean newerThan(DataVersion arg0) {
| return false;
| }} );
| return option;
| }
It causes this exception:
Bad things happened when I tried to remove custard
| org.jboss.cache.CacheException: Must be in a valid transaction _remove; id:5(null, /custard, true)
| at org.jboss.cache.interceptors.OptimisticNodeInterceptor.invoke(OptimisticNodeInterceptor.java:66)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor.invoke(OptimisticCreateIfNotExistsInterceptor.java:69)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.OptimisticValidatorInterceptor.invoke(OptimisticValidatorInterceptor.java:84)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.OptimisticLockingInterceptor.invoke(OptimisticLockingInterceptor.java:126)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.TxInterceptor.handleNonTxMethod(TxInterceptor.java:365)
| at org.jboss.cache.interceptors.TxInterceptor.invoke(TxInterceptor.java:160)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.CacheMgmtInterceptor.invoke(CacheMgmtInterceptor.java:183)
| at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:5776)
| at org.jboss.cache.TreeCache.remove(TreeCache.java:3855)
| at org.jboss.cache.TreeCache.remove(TreeCache.java:3438)
| at com.medq.test.TestTreeCacheNotInTransaction$1.afterCompletion(TestTreeCacheNotInTransaction.java:47)
| at org.jboss.cache.transaction.DummyTransaction.notifyAfterCompletion(DummyTransaction.java:270)
| at org.jboss.cache.transaction.DummyTransaction.commit(DummyTransaction.java:64)
| at org.jboss.cache.transaction.DummyBaseTransactionManager.commit(DummyBaseTransactionManager.java:61)
| at com.medq.test.TestTreeCacheNotInTransaction.main(TestTreeCacheNotInTransaction.java:32)
|
Is this expected behaviour for JBoss Cache? If so I will raise the issue on the Hibernate forum.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4027691#4027691
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4027691
19Â years, 1Â month
[Installation, Configuration & Deployment] - Interesting behavoir when debugging app in eclipse with Jbos
by etornick
I noticed this very interesting behavoir when debugging a simple web app in myEclipse with Jboss. ( I am using the latest version of jboss)
I was wondering if anyone knew anything about this. I have done quite a bit of searching for this and couldn't find an explanation.
When editing jsp files in eclipse, upon file save the files are deployed to jboss. This works perfectly. When refreshing the browser the new jsp executes. This is hot deploy working as I expected.
When I change code in a java package that is a bean used by the jsp this is where the behavoir is strange. I noticed that the class file is immediately deployed to jboss upon the file save.
However when I step through the debugger it appears to execute the new code but the output is from the old class.
If I bring up a new browser and do the same test then the code steps through as before but this time the code is executing correctly. It is as if the old class is actually cached somewhere and is used unless I start up a new browser.
Just as a test, I repeated the test and this time I deleted the class from the server deploy diretory and sure enough, with the same browser I used just before deleting the class, the code stepped through the debugger as if the class was still there, and returned the old values.
If I brought up a new browser I got an error that the class wasn't there.
It is as if jboss is caching the java class somewhere.
I read about the cache product but I am not using that, I am just using the basic jboss server.
This is not a problem as I can still make progress with what I am working on. I just have to know to either re-deploy when making a change to any java code or bring up a new browser to see the latest deployed code. I am just curious if anyone knows why this is happening.
Thanks in advance for any insights.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4027689#4027689
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4027689
19Â years, 1Â month
[JBoss Seam] - Component with custom scope and configuration
by quilleashm
Hi there,
I have a situation where I have several different configurations for my hibernate sessions, mainly revolving around different interceptors and filters. I also sometimes want the session to be event scoped and other times to be conversation scoped.
At the moment I have something similar to the ManagedHibernateSession which handles closing the session on the @Destroy of the component. This is all fine.
But now because I have all these different configuration options I don't really want to have to define an entry in component.xml for each property combination. I want to be able to do something like this in code...
| Sessions.getSession( ScopeType.EVENT, enableInterceptors, enableFilters ... );
|
And have the a Session returned that will be created on demand with the correct configuration AND stored in the relevant Seam context so it is cleaned up in the right place.
Almost like wanting to add arbitrary objects to the Seam contexts and have them cleaned up like normal Seam components.
I can't see anyway of doing this right now as the Seam stuff all revolves around the Component entry being in place. Is there any way of making this a bit more dynamic. I thought about having a Seam component per scope that stores a list of objects and does the relevant lifecycle stuff do them (calling a destory method for example).
Has anyone else tried to do something like this or have a better way within Seam of doing this?
Cheers.
Mike.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4027680#4027680
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4027680
19Â years, 1Â month