I am trying to define a JPA @Converter for Joda-Time which gets put in an EJB JAR along with the result of the JPA @Entity and a @Stateless session bean like this:
@Converter(autoApply = true)
public class LocalDateConverter implements
AttributeConverter<LocalDate, String> {
@Override
public String convertToDatabaseColumn(final LocalDate localDate) {
if (localDate == null) {
return null;
}
return localDate.toString();
}
@Override
public LocalDate convertToEntityAttribute(final String dbData) {
if (dbData == null) {
return null;
}
return LocalDate.parse(dbData);
}
}
I have a session bean that looks like:
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class VenueTableModule {
@PersistenceContext
EntityManager em;
public Bar foo() {
final Bar bar = new Bar ();
bar.name = "foo" + UUID.randomUUID();
bar.startDate = LocalDate.now();
em.persist(bar);
em.flush();
return bar;
}
}
which fails on the em.persist(bar) line when I invoke it from the servlet. The code works without the em.* lines I don't get the error when the converter, stateless session beans, etc. are moved to the web application which I know is allowed and I may have to do it. So it appears that the @Converter is using a different class loader than the rest of the EJB jar.
I am using Glassfish 4.0, and I am not sure if it is a bug GLASSFISH-21161 or if I am just doing something incorrectly. However, the code I have seems to work with WildFly