| ||||||||||
Resin 3.1 Documentation Examples 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: <?xml version="1.0" encoding="UTF-8"?> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd" version="1.0"> <package>qa</package> <entity name="Test" class="qa.Test" access="PROPERTY"> <table name="TEST"/> <attributes> <id name="id"> <column name="ID"/> </id> <basic name="data"> <column name="DATA"/> </basic> <many-to-one name="parent"> <join-column name="FK_PARENT"/> </many-to-one> </attributes> </entity> </entity-mappings> Non-Transactional LifecycleAmber's non-transactional lifecycle has three important states:
In the diagram below, the red methods ( The Calling Calling The // 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:
|