Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Converter not being picked up despite having autoApply=true

På torsdag 04. juli 2013 kl. 16:12:17, skrev Andreas Joseph Krogh <andreak@xxxxxxxxxxxx>:
På torsdag 04. juli 2013 kl. 15:26:23, skrev Guy Pelletier <guy.pelletier@xxxxxxxxxx>:
Hi Andreas,

Not knowing the full details of the spring package scan tool, I suspect the @Converter class is not being returned from this scan and would explain why it is not being applied by EclipseLink.

Perhaps you could try including a persistence.xml file as a test and make sure the converter is listed there.

<class>JodaDateTimeConverter</class>


Also, if you have debugging capabilities, you could try looking at initPersistenceUnitClasses from org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor. That is where the @Converter would be picked up if found.
 
Adding the following persistence.xml makes it work, both ddl-creation and inserting/retrieving:
 
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.1">
        <persistence-unit name="default">
                <class>no.officenet.test.hibernatetest.infrastructure.jpa.JodaDateTimeConverter</class>
        </persistence-unit>
</persistence>
 
So it seems it's Spring's package-scanning tool which needs to be updated to also add @Converter classes?
 
I added a custom PersistenceUnitPostProcessor to add @Converter classes:
public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {

        ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
        provider.addIncludeFilter(new AnnotationTypeFilter(Converter.class));

        for (BeanDefinition definition : provider.findCandidateComponents(basePackage)) {

                LOG.debug("Registering classpath-scanned entity %s in persistence unit info!", definition.getBeanClassName());
                pui.addManagedClassName(definition.getBeanClassName());
        }

}
It now works very well.
 
Thanks for all the help!
 
--
Andreas Joseph Krogh <andreak@xxxxxxxxxxxx>      mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc
 

Back to the top