[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5722) Method annotated with @PreUpdade is not called
Oleksandr Alesinskyy (JIRA)
noreply at atlassian.com
Tue Nov 9 14:45:13 EST 2010
Method annotated with @PreUpdade is not called
----------------------------------------------
Key: HHH-5722
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5722
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 3.6.0
Environment: Java 1.6.0_21, Windows and Linux
Reporter: Oleksandr Alesinskyy
I have a class with methods annotated @PostLoad, @PrePersist, and @PreUpdate as below:
{code:title=Snippet}
@Transient
private B2BCustomerKeyPo b2BCustomerKey;
@Embedded
@AttributeOverrides( { @AttributeOverride(name = "username", column = @Column(name = "APPLICATION_NAME")),
@AttributeOverride(name = "b2BCustomerName", column = @Column(name = "B2BCUSTOMER_NAME")) })
private UserKeyPo applicationKey;
...
@SuppressWarnings("unused")
@PostLoad
private void postLoad() {
if (applicationKey != null) {
if (applicationKey.getB2BCustomerName() != null) {
b2BCustomerKey = new B2BCustomerKeyPo(applicationKey.getB2BCustomerName());
}
if (applicationKey.getUsername() == null) applicationKey = null;
}
}
@SuppressWarnings("unused")
@PrePersist
private void prePersist() {
if (b2BCustomerKey != null) {
if (applicationKey != null) {
if (!b2BCustomerKey.equals(new B2BCustomerKeyPo(applicationKey.getB2BCustomerName()))) {
final String msg =
String
.format(
"B2B customer [%s] of the product does not match the Application of the product [%s/%s]",
b2BCustomerKey.getName(), applicationKey.getB2BCustomerName(),
applicationKey.getUsername());
throw new IllegalStateException(msg);
}
} else {
applicationKey = new UserKeyPo(b2BCustomerKey.getName(), null);
}
}
}
@SuppressWarnings("unused")
@PreUpdate
private void preUpdate() {
throw new RuntimeException("§TEST§");
}
{code}
prePersist and postLoad methods work as expected but preUpdate method is not called at all - while updated fields are dutifully written into DB (they never would if preUopdate will be called).
The code manipulating the object is as below:
{code:title=Snippet2}
ProductPo productPoOld = readProductPo(input.getProduct().getProductKey().getExternalProductKey());
...
B2BCustomerKey b2bCustomerKey = productNew.getB2BCustomerKey();
productPoOld.setB2BCustomerKey(mappingHelper.mapObject(productNew.getB2BCustomerKey(),
B2BCustomerKeyPo.class));
LOG.debug(productPoOld.getB2BCustomerKey());
// @PreUpdate method is not called regardless if flush is present below or not
productDao.flush();
{code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list