|
Re: Filtering a OneToMany relationship [message #531611 is a reply to message #531440] |
Wed, 05 May 2010 14:56 |
Gilberto Caetano de Andrade Messages: 45 Registered: July 2009 |
Member |
|
|
JSR-317 Final Release:
Quote: |
3.5.2 Semantics of the Life Cycle Callback Methods for Entities
.
.
.
The PostLoad method for an entity is invoked after the entity has been loaded into the current persistence context from the database or after the refresh operation has been applied to it. The PostLoad method is invoked before a query result is returned or accessed or before an association is traversed. It is implementation-dependent as to whether callback methods are invoked before or after the cascading of the lifecycle events to related entities. Applications should not depend on this ordering.
.
.
.
3.5.3 Example
@Entity
@EntityListeners(com.acme.AlertMonitor.class)
public class Account {
Long accountId;
Integer balance;
boolean preferred;
@Id
public Long getAccountId() { ... }
...
public Integer getBalance() { ... }
...
@Transient // because status depends upon non-persistent context
public boolean isPreferred() { ... }
...
public void deposit(Integer amount) { ... }
public Integer withdraw(Integer amount) throws NSFException {... }
@PrePersist
protected void validateCreate() {
if (getBalance() < MIN_REQUIRED_BALANCE)
throw new AccountException("Insufficient balance to open an
account");
}
@PostLoad
protected void adjustPreferredStatus() {
preferred =
(getBalance() >= AccountManager.getPreferredStatu-
sLevel());
}
}
public class AlertMonitor {
@PostPersist
public void newAccountAlert(Account acct) {
Alerts.sendMarketingInfo(acct.getAccountId(), acct.getBal-
ance());
}
}
|
You've got the idea!
Gilberto
[Updated on: Wed, 05 May 2010 14:59] Report message to a moderator
|
|
|
|
|
|
|
Re: Filtering a OneToMany relationship [message #531988 is a reply to message #531440] |
Thu, 06 May 2010 17:24 |
|
In EclipseLink you can use a DescriptorCustomizer (@Customizer) to set an additionalJoinExpression for you class that will filter all "deleted"=true rows for every query.
You can also customize the selectionCriteria per mapping.
EclipseLink also have full history support that will automatically maintain a mirror table with a history of changes and a start and end column.
James : Wiki : Book : Blog : Twitter
|
|
|
Powered by
FUDForum. Page generated in 0.03641 seconds