Java Reference
In-Depth Information
Easier development —There is less cognitive load because rather than being
forced to think about everything—business logic, persistence, transactions
etc.—at once you can instead focus on one thing at a time. You can first
design and implement the business logic and then, once that is working,
you can deal with persistence and transactions.
Faster development —You can develop and test your business logic outside of
the application server and without a database. You do not have to package
your code and deploy it in the application. Also, you do not have to keep
the database schema constantly in sync with the object model or spend time
waiting for slow-running database tests to finish. Tests can run in a few sec-
onds and development can happen at the speed of thought—or at least as
fast as you can type!
Improved portability —You are not tied to a particular implementation tech-
nology. The cost of switching to the next generation of Java technology is
minimized because you have to rewrite only a small amount of code, if any.
I was genuinely surprised by how POJO s changed how I went about development
because I'd become so accustomed to the cumbersome EJB approach. As with the
TiVo box I described earlier, I had to use them before I appreciated their true
value. But now I couldn't imagine reverting to the old way of working. Of course,
you still need to handle persistence and transactions, which is where lightweight
frameworks come in.
1.2.3
Persisting POJOs
When the time comes to persist the POJO s that implement the business logic,
there are some powerful object/relational mapping frameworks to choose from.
The main ones are JDO , which is a standard from Sun, and Hibernate, which is an
extremely popular open source framework. In addition, the specification for EJB 3
entity beans appears to be potentially quite powerful.
Transparent persistence with JDO and Hibernate
JDO and Hibernate provide transparent persistence, which means that the classes
are unaware that they are persistent. The application just needs to call the persis-
tence framework API s to save, query, and delete persistent objects. The persis-
tence framework automatically generates the SQL statements that access the
database using an object/relational mapping, which is defined by XML docu-
ments or Java 5 annotations. The object/relational mapping specifies how classes
map to tables, fields map to columns, and relationships map to either foreign keys
 
 
 
 
 
 
 
Search WWH ::




Custom Search