我有一個EmebeddedId
的實體。正如預期的那樣,正在觸發實體上的實體監聽器(在加載時修剪空白空間Strings
),因此根本沒有觸發編號爲Embeddable
的相同監聽器。如何觸發可嵌入的EntityListener
我做錯了嗎?它如何被修復?
實體:
@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());
}
}
}
...
感謝,MADA,非常有意義。我想我必須擴展偵聽器來傳播修剪到嵌入類。 – kostja