Issue 1:
Sharif Uddin opened SPR-5007 and commented

HibernateTemplate.loadAll(clazz) returns duplicate entries if the Class 'clazz' contains collection field and database contains entry related to that collection field.

for example,

A Customer contains list of Product (one-to-many).

In database say there are Products p1,p2 for customer c1 and Product p3 for Customer c2.

Now ..loadAll(Customer.class) returns a list contains {c1,c1,c2}.

related class: org.springframework.orm.hibernate3.HibernateTemplate

related method:

public List loadAll(final Class entityClass) throws DataAccessException {

return (List) executeWithNativeSession(new HibernateCallback() {

public Object doInHibernate(Session session) throws HibernateException {

Criteria criteria = session.createCriteria(entityClass);

prepareCriteria(criteria);

return criteria.list();

}

});

}

Possible Solution:

changing the line

Criteria criteria = session.createCriteria(entityClass);

to

Criteria criteria = session.createCriteria(entityClass).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

Affects: 2.5.5

Issue 2:
Ivan Sopov opened SPR-9845 and commented

If I inject javax.inject.Provider for creating prototype scoped beans into session scoped beans it fails when creating second session:

2012-10-01 18:45:50.113:WARN::/pins/default

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionBeanWithDefaultProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.inject.Provider com.sopovs.moradanen.SessionBeanWithDefaultProvider.prototypePojoProvider; nested exception is java.lang.IllegalArgumentException: Can not set javax.inject.Provider field com.sopovs.moradanen.SessionBeanWithDefaultProvider.prototypePojoProvider to com.sopovs.moradanen.PrototypeBean

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:332)

at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)

at org.springframework.web.context.request.SessionScope.get(SessionScope.java:92)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)

at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectFactory.getObject(DefaultListableBeanFactory.java:1040)

at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyProvider.get(DefaultListableBeanFactory.java:1056)

at com.sopovs.moradanen.DefaultProviderController.sayHello(DefaultProviderController.java:19)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...

I have created sample project reproducing the issue and published it on github: https://github.com/isopov/provider-in-session-with-spring

Affects: 3.1.2

Reference URL: https://github.com/isopov/provider-in-session-with-spring

Issue Links:

#13819 @Inject Provider or @Autowired ObjectFactory issue with session scoped bean ("duplicates")