![]() |
| |||||||||
| Resin 3.1 Documentation Tutorials Changes Overview Installation Configuration Quercus SOA/IoC JSP Servlets and Filters Admin (JMX) EJB Amber Security Performance Hessian XML and XSLT Third-party Troubleshooting/FAQ Amber Lifecycle @Table |
The Amber bean lifecycle follows the JPA model. Amber supports both transactional and non-transactional lifecycles. Example configurationThe lifecycle description uses a single running example, Test, which
has two properties:
<hibernate-mapping>
<class name="qa.Test">
<id name="id"/>
<property name="data"/>
<many-to-one name="parent"/>
</class>
</hibernate-mapping>
Non-Transactional LifecycleAmber's non-transactional lifecycle has three important states:
In the diagram below, the red methods ( ![]() The Calling Calling The state represents lazily-loaded entities. many-to-one
relations and some queries will return the unloaded bean instead of
a loaded bean. When the application calls a
// load() queries the database and puts test in the clean state
qa.Test test = aConn.load(qa.Test.class, "1");
// getter calls remain in the clean state
System.out.println(test.getData());
// setters change to the dirty state
test.setData("foo");
// parent is lazily-loaded in the hollow state.
qa.Test parent = test.getParent();
// the getter loads parent from the database and changes to the clean state
System.out.println(parent.getData());
// the flush updates test and changes back to the clean state
aConn.flush();
// closing the connection changes all beans to the transient state
aConn.close();
Transactional LifecycleIn a transaction, Amber loads the bean from the database, even if it was loaded outside of the transaction. (Exceptions exist for cases like read-only beans.) By loading the bean in the transaction, Amber lets the database handle the transactional locking and state consistency. Just like the non-transactional and states, Amber has transactional and states called and . As in the non-transactional case, the state represents lazily-loaded beans.
![]() The main differences from the non-transactional lifecycle are:
| |||||||||