I have an entity with an EmebeddedId. The entity listener (trims whitepace off Strings on load) on the the entity is being triggered as expected, the same listener on the id Embeddable is not triggered at all.
Am I doing it wrong? How can it be fixed?
Entity:
@Entity
@Table(name = "SUBMITTER_VIEW")
@EntityListeners(TrimListener.class)
public class Submitter implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private SubmitterPK id;
@Trim
@Column(name = "DOC_NAME")
private String name;
...
Embeddable:
@Embeddable
@EntityListeners(TrimListener.class)
public class SubmitterPK implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "LSTORT")
private String bsnr;
@Trim
@Column(name = "LOGIN")
private String login;
...
Listener:
public class TrimListener {
Logger log = LoggerFactory.getLogger("TrimListener");
@PostLoad
public void repairAfterLoad(final Object entity) throws IllegalAccessException {
log.debug("trimlistener active");
final Set<Field> trimProps = getTrimProperties(entity.getClass());
for (final Field fieldToTrim : trimProps) {
final String propertyValue = (String) fieldToTrim.get(entity);
if (propertyValue != null) {
fieldToTrim.set(entity, propertyValue.trim());
}
}
}
...
I think it’s plainly ignored because it’s not a standard place where JPA 2.0 expects it. According to JPA 2.0 final spec, an entity listener may be an entity, a mapped superclass or a listener associated in one of those (see section 3.5 of the spec):