HotswapProjects / HotswapAgent

Java unlimited redefinition of classes at runtime.
GNU General Public License v2.0
2.33k stars 491 forks source link

hibernate plugin: AttributeConverter not used on reload #370

Open cdalexndr opened 4 years ago

cdalexndr commented 4 years ago

I have the following attribute converter:

@Converter(autoApply = true)
public class URLToStringConverter implements AttributeConverter<URL, String>

On startup database validation succeeds, but on reload I get invalid type errors, because the attribute converter is not used, it falls back to SerializableType which is VARBINARY sql type instead of expected VARCHAR (string) type: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [url] in table [image]; found [text (Types#VARCHAR)], but expecting [varchar (Types#VARBINARY)]

Using Spring Boot 2.3.3 HOTSWAP AGENT: 21:46:49.652 INFO (org.hotswap.agent.config.PluginRegistry) - Plugin 'org.hotswap.agent.plugin.hibernate.HibernatePlugin' initialized in ClassLoader 'jdk.internal.loader.ClassLoaders$AppClassLoader@2437c6dc'. HOTSWAP AGENT: 21:46:49.653 INFO (org.hotswap.agent.plugin.hibernate.HibernatePlugin) - Hibernate plugin initialized - Hibernate Core version '5.4.20.Final'

cdalexndr commented 4 years ago

Trying a workaround to manually add attribute converters using MetadataBuilderContributor causes startup to fail because of duplicate attribute converter.

cdalexndr commented 4 years ago

After some debugging it seems that Spring uses DefaultPersistenceUnitManager.buildDefaultPersistenceUnitInfo to scan for @Converter classes and registers them, so they work at startup. I guess this plugin doesn't interoperate with Spring so the reload doesn't use the same initialization mechanism as spring at startup.