|
From: Hunter K. <re...@ei...> - 2004-04-02 10:34:59
|
[ This was already sent to the user list, it was suggested I send it on
to the developers list.]
There is some strange behaviour with CGLIB proxied objects and instance
fields. Sometime it returns the field of the CGLIB proxy itself, and
sometimes of the target object, which causes some very unexpected behaviour,
to say the least.
This is similar to the thread of yesterday, but it petered out somewhat
inconclusively. I've boiled it down to a pretty simple sample.
The results are as follows (skipping the initial spring setup stuff):
INFO: Creating implicit proxy for bean 'sampleCommand' with 1 common
interceptors and 0 specific interceptors
02-Apr-2004 10:45:22
org.springframework.transaction.support.AbstractPlatformTransactionManager
commit
INFO: Initiating transaction commit
returned result: <no result>
02-Apr-2004 10:45:22
org.springframework.transaction.support.AbstractPlatformTransactionManager
commit
INFO: Initiating transaction commit
method call result: RealCommand result: 3
direct method call result: RealCommand result: 3
Here's the java class and the config file. The only thing that anyone should
need to change is the properties of the data source...
-- SampleCommand.java
package sample;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SampleCommand
{
public static final ApplicationContext appContext =
initializeAppContext();
private static ApplicationContext initializeAppContext()
{
ClassPathXmlApplicationContext ctx = new
ClassPathXmlApplicationContext("sampleContext.xml");
return ctx;
}
String _result = "<no result>";
public final String execute()
{
executeCommand();
return _result;
}
public final String executeUsingMethod()
{
executeCommand();
return getResult();
}
public String getResult()
{
return _result;
}
int _foo;
public void setFoo(int foo)
{
_foo = foo;
}
public void executeCommand()
{
_result = "RealCommand result: "+_foo;
}
public static void main(String[] args)
{
SampleCommand c = (SampleCommand) appContext.getBean("sampleCommand");
c.setFoo(3);
System.out.println("returned result: "+c.execute());
System.out.println("method call result: "+c.executeUsingMethod());
System.out.println("direct method call result: "+c.getResult());
}
}
-- sampleContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="sampleCommand" class="sample.SampleCommand"/>
<!-- Transaction Interceptor set up to do PROPAGATION_REQUIRED on execute
methods for Command objects-->
<bean id="executeMethodTxnAS"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<props>
<prop key="execute*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="commandExecuteMethodTxnInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager"><ref
local="transactionManager"/></property>
<property name="transactionAttributeSource">
<!-- I think this uses the spiffy TransactionAttributeSourceEditor,
obviating the need for a seperate
TransactionAttributeSource definition in simple cases -->
<!--
value>com.newbay.mixxe.command.Command.execute=PROPAGATION_REQUIRED</value
-->
<ref local="executeMethodTxnAS"/>
</property>
</bean>
<!-- One BeanNameAutoProxyCreator handles all beans where we want
transactions (ie Command.execute) -->
<bean id="autoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="interceptorNames">
<list><idref local="commandExecuteMethodTxnInterceptor"/></list>
</property>
<property name="proxyTargetClass"><value>true</value></property>
<!-- property name="exposeProxy"><value>true</value></property -->
<property name="beanNames">
<list><value>*Command</value></list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property
name="driverClassName"><value>org.postgresql.Driver</value></property>
<property
name="url"><value>jdbc:postgresql://localhost/mixxe</value></property>
<property name="username"><value>mixxe</value></property>
<property name="password"><value>mixxe</value></property>
</bean>
</beans>
|
|
From: Hunter K. <re...@ei...> - 2004-04-05 09:58:19
|
[ Sorry if this is a repost. I sent this on Friday, but didn't receive a
copy, and since there isn't an archive of the list yet, I wasn't able
to check if it was delivered. This was already sent to the user list, it was
suggested I send it on to the developers list.]
There is some strange behaviour with CGLIB proxied objects and instance
fields. Sometime it returns the field of the CGLIB proxy itself, and
sometimes of the target object, which causes some very unexpected behaviour,
to say the least.
This is similar to the thread of yesterday, but it petered out somewhat
inconclusively. I've boiled it down to a pretty simple sample.
The results are as follows (skipping the initial spring setup stuff):
INFO: Creating implicit proxy for bean 'sampleCommand' with 1 common
interceptors and 0 specific interceptors
02-Apr-2004 10:45:22
org.springframework.transaction.support.AbstractPlatformTransactionManager
commit
INFO: Initiating transaction commit
returned result: <no result>
02-Apr-2004 10:45:22
org.springframework.transaction.support.AbstractPlatformTransactionManager
commit
INFO: Initiating transaction commit
method call result: RealCommand result: 3
direct method call result: RealCommand result: 3
Here's the java class and the config file. The only thing that anyone should
need to change is the properties of the data source...
-- SampleCommand.java
package sample;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SampleCommand
{
public static final ApplicationContext appContext =
initializeAppContext();
private static ApplicationContext initializeAppContext()
{
ClassPathXmlApplicationContext ctx = new
ClassPathXmlApplicationContext("sampleContext.xml");
return ctx;
}
String _result = "<no result>";
public final String execute()
{
executeCommand();
return _result;
}
public final String executeUsingMethod()
{
executeCommand();
return getResult();
}
public String getResult()
{
return _result;
}
int _foo;
public void setFoo(int foo)
{
_foo = foo;
}
public void executeCommand()
{
_result = "RealCommand result: "+_foo;
}
public static void main(String[] args)
{
SampleCommand c = (SampleCommand) appContext.getBean("sampleCommand");
c.setFoo(3);
System.out.println("returned result: "+c.execute());
System.out.println("method call result: "+c.executeUsingMethod());
System.out.println("direct method call result: "+c.getResult());
}
}
-- sampleContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="sampleCommand" class="sample.SampleCommand"/>
<!-- Transaction Interceptor set up to do PROPAGATION_REQUIRED on execute
methods for Command objects-->
<bean id="executeMethodTxnAS"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<props>
<prop key="execute*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="commandExecuteMethodTxnInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager"><ref
local="transactionManager"/></property>
<property name="transactionAttributeSource">
<!-- I think this uses the spiffy TransactionAttributeSourceEditor,
obviating the need for a seperate
TransactionAttributeSource definition in simple cases -->
<!--
value>com.newbay.mixxe.command.Command.execute=PROPAGATION_REQUIRED</value
-->
<ref local="executeMethodTxnAS"/>
</property>
</bean>
<!-- One BeanNameAutoProxyCreator handles all beans where we want
transactions (ie Command.execute) -->
<bean id="autoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="interceptorNames">
<list><idref local="commandExecuteMethodTxnInterceptor"/></list>
</property>
<property name="proxyTargetClass"><value>true</value></property>
<!-- property name="exposeProxy"><value>true</value></property -->
<property name="beanNames">
<list><value>*Command</value></list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property
name="driverClassName"><value>org.postgresql.Driver</value></property>
<property
name="url"><value>jdbc:postgresql://localhost/mixxe</value></property>
<property name="username"><value>mixxe</value></property>
<property name="password"><value>mixxe</value></property>
</bean>
</beans>
|
|
From: Jean-Baptiste B. <jb...@br...> - 2004-04-05 14:29:30
|
Hello Spring framework makers !
I heard about Hibernate "module" in Spring framework.
I found an ORM package with a Hibernate package in it.
Where can I find info of the design for the classes
in ...orm.hibernate package ?
I found an orm.jdo package too.
Some classes are present in both packages like XXXTransactionManager :
JdoTransactionManager and HibernateTransactionManager.
But some are not present in both packages.
Anyone can explain me the design around that ?
(or http pointer ...)
The HibernateTransactionManager implements "only" InitializingBean.
I was waiting for a super interface common to jdo and hibernate.
Thanks a lot !
________________________________________________
Jean-Baptiste BRIAUD SYSDEO
www.sysdeo.com
software engineer www.eclipsetotale.com
|