Is it possible to write a generic enum converter for JPA?

Based on @scottb solution I made this, tested against hibernate 4.3: (no hibernate classes, should run on JPA just fine) Interface enum must implement: public interface PersistableEnum<T> { public T getValue(); } Base abstract converter: @Converter public abstract class AbstractEnumConverter<T extends Enum<T> & PersistableEnum<E>, E> implements AttributeConverter<T, E> { private final Class<T> clazz; public AbstractEnumConverter(Class<T> … Read more

JPA: JOIN in JPQL

Join on one-to-many relation in JPQL looks as follows: select b.fname, b.lname from Users b JOIN b.groups c where c.groupName = :groupName When several properties are specified in select clause, result is returned as Object[]: Object[] temp = (Object[]) em.createNamedQuery(“…”) .setParameter(“groupName”, groupName) .getSingleResult(); String fname = (String) temp[0]; String lname = (String) temp[1]; By the … Read more

Is it possible to output generated SQL using EclipseLink without having to increase log verbosity?

Put the following properties in your persistence.xml: <property name=”eclipselink.logging.level.sql” value=”FINE”/> <property name=”eclipselink.logging.parameters” value=”true”/> The latter is helpful, so that the values of the parameter are shown. An alternative is using log4jdbc or log4jdbc-remix.

Java8 Collections.sort (sometimes) does not sort JPA returned lists

Well, this is a perfect didactic play telling you why programmers shouldn’t extend classes not designed for being subclassed. Books like “Effective Java” tell you why: the attempt to intercept every method to alter its behavior will fail when the superclass evolves. Here, IndirectList extends Vector and overrides almost all methods to modify its behavior, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)