我有一个带有EmebeddedId
. 实体上的实体侦听器(在加载时修剪空白Strings
)正在按预期Embeddable
触发,根本不会触发 id 上的相同侦听器。
我做错了吗?如何修复?
实体:
@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
@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;
...
听众:
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());
}
}
}
...