Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing SessionFactory property (filter AutoCloseable from PropertyDescriptors) #29480

Closed
v00d00c0de opened this issue Nov 14, 2022 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@v00d00c0de
Copy link

v00d00c0de commented Nov 14, 2022

Affects: 5.3.20+

Before 5.3.20 the following code worked as intended (note the use of <util:property-path path="abcEntityManagerFactory.sessionFactory" />: sessionFactory property is accessible in abcEntityManagerFactory bean)

<bean id="abcEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" lazy-init="true">
		... providing the relevant properties ...
</bean>
<bean id="abcHibernateStatisticsMBeanExporter" class="org.springframework.jmx.export.MBeanExporter">
	<property name="server" ref="mbeanServer" />
	<property name="beans">
	   <map>
	      <entry key="org.example:name=abcHibernateStatistics">
		<bean class="org.hibernate.stat.internal.StatisticsImpl">
                    <constructor-arg name="sessionFactory">
                        <util:property-path path="abcEntityManagerFactory.sessionFactory" />
                    </constructor-arg>
                    <property name="statisticsEnabled" value="true"/>
                  </bean>
	      </entry>
	   </map>
	</property>
</bean>

After upgrading from Spring 5.3.18 to 5.3.23 the system fails on startup with the following exception:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'util:property-path#61ffe4cf': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.NotReadablePropertyException: Invalid property 'sessionFactory' of bean class [com.sun.proxy.$Proxy231]: Bean property 'sessionFactory' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:176)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:135)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:377)
	... 72 more
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'sessionFactory' of bean class [com.sun.proxy.$Proxy231]: Bean property 'sessionFactory' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
	at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:627)
	at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:617)
	at org.springframework.beans.factory.config.PropertyPathFactoryBean.getObject(PropertyPathFactoryBean.java:223)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169)
	... 74 more

This is caused by #28445 which is a part of 5.3.20.

SessionFactory property is no longer accessible: its type is org.hibernate.engine.spi.SessionFactoryImplementor which is AutoCloseable. And according to the new isInvalidReadOnlyPropertyType method added in #28445 it is filtered out of the bean's PropertyDescriptors.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 14, 2022
@jhoeller
Copy link
Contributor

jhoeller commented Nov 14, 2022

I see your point, and there might be a way to fine-tune that rule towards accepting AutoCloseable property types on declaring classes that are AutoCloseable themselves.

That said, there are other ways to express such a dereference in configuration scenarios, e.g. using SpEL:
<constructor-arg name="sessionFactory" value="#{abcEntityManagerFactory.sessionFactory}"/>

Or alternatively, using an intermediate bean definition:

<constructor-arg name="sessionFactory">
    <bean factory-bean="abcEntityManagerFactory" factory-method="getSessionFactory"/>
</constructor-arg>

I would generally recommend either of the two over a JavaBeans property for such purposes.

@jhoeller jhoeller self-assigned this Nov 14, 2022
@jhoeller jhoeller added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 14, 2022
@jhoeller jhoeller added this to the 5.3.24 milestone Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants