I can't speak to what the specific issue is without looking at the
code, but you might try this to confirm this works:
//1 make sure u have a reference to a HibernateTransactionManager (the
PlatformTransactionManager). if you don't have one, then its easy to
create. this will be a problem later, regardless, so create one. All
it needs is a reference to the SessionFactory.
//2 then, for this example, try creating a TransactionTemplate
TransactionTemplate tt =new TransactionTemplate(
hibernateTransactionManager ) ;
tt.execute(new TransactionCallback<Object>(){
public Object doInTransaction(TransactionStatus status) {
// your logic here
HibernateTemplate template = .... ;
template.setFilterName("deletedFilter");
}
});
if this works, then indeed, you need to wrap the operation in a
transaction, preferably using declarative transaction management
(e.g., @Transactional). For more on that please consult the
documentation, but it should be as simple as using the
tx:annotation-driven namespace and providing it with a reference to
that transaction manager:
<tx:annotation-driven transaction-manager = "hibernateTransactionManager"
/>
The first responder's right, though, this is probably not the
appropriate forum for this question, however. Feel free to ping me or
follow up on StackOverflow or the Spring forums
(
forum.springsource.org).
HTH...
Thanks,
Josh Long
Spring Developer Advocate, SpringSource, a division of VMware
Co-Author of Apress' "Spring Enterprise Recipes," "Spring Recipes, 2nd
Edition" and "Pro Spring Integration"
http://www.joshlong.com |
http://twitter.com/starbuxman
Infoq.com editor (
http://www.infoq.com/author/Josh-Long)
On Wed, Oct 12, 2011 at 2:41 AM, Strong Liu <stliu(a)hibernate.org> wrote:
isn't this a spring question?
-----------
Strong Liu <stliu(a)hibernate.org>
http://hibernate.org
http://github.com/stliu
On Oct 12, 2011, at 5:09 PM, Ankita Patil wrote:
> Hi,
> As i have integrated spring in hibernate i have to create a hibernate template. so i
have to create my filters using this hibernate template.
>
> HibernateTemplate template = super.createHibernateTemplate(sessionFactory);
> template.setFilterName("deletedFilter");
>
> Now i have to use the setParameter() method on the filter.
>
> template.enableFilter("deletedFilter").setParameter("isdeleted",
false);
>
> But on doing this I am getting the following exception :
>
> Exception in thread "main"
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'subscriberAccessor' defined in class path resource
[applicationContext-storage.xml]: Cannot resolve reference to bean 'subscriberDao'
while setting constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'subscriberDao' defined in class path resource [hibernatespring-common.xml]: Error
setting property values; nested exception is
org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions
(1) are:
> PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'sessionFactory' threw exception; nested exception is
java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration
does not allow creation of non-transactional one here
> at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
> at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
> at
org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:586)
> at
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140)
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:984)
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:886)
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
> at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
> at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
> at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
> at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
> at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
> at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
> at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
> at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
> at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
> at com.germinait.common.spring.SpringUtils.getBean(SpringUtils.java:68)
> at
com.germinait.common.study.db.dao.StudyFeaturesHome.main(StudyFeaturesHome.java:166)
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'subscriberDao' defined in class path resource
[hibernatespring-common.xml]: Error setting property values; nested exception is
org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions
(1) are:
> PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'sessionFactory' threw exception; nested exception is
java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration
does not allow creation of non-transactional one here
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1341)
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
> at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
> at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
> at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
> at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
> at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
> ... 18 more
> Caused by: org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
> PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'sessionFactory' threw exception; nested exception is
java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration
does not allow creation of non-transactional one here
> at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
> at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1338)
>
> Is there anyway so that i can set the value for the parameter of the filter?
>
> Thanks,
> Ankita
> _______________________________________________
> hibernate-users mailing list
> hibernate-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/hibernate-users
-----BEGIN PGP SIGNATURE-----
iQEcBAEBAgAGBQJOlWDPAAoJEP7OOVN4L0j1oq8H/2cfsrrhYnmPmrqzdmmZx2bR
D9APyYAoN6D+Mdk9QqMPgo0rNzT1AWc/XzDBgrzNgtctGP541Ac8ndhcMCJAbZEo
gUGPvZa6SEiMFCXWaNvVyDTPUvGqPCnifPXVEhRlszXzj6cNY518afvJ5jlE37vP
Ow9ApQGo8VZsGmLGOrjIsJWudSxDEF27RoHTBOZk9o/Um4Mrl4a0YO2xuPckM1oa
s7s33URtgERI61E053tfYbgT5TVu4ZJYOqx1HRZQ/rN3z2ozhnF6ma04GxrzB8ND
sbcJkglE0jz6+8YiRA7oa8Fgj9wZO5ww7yvUGAD8f1+jDKU69rhwDybaLg4kG5k=
=RyBU
-----END PGP SIGNATURE-----
_______________________________________________
hibernate-users mailing list
hibernate-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-users