Struts Recipes: Hibernate and Struts: "Persistence of data is a tedious and laborious job. To make matters worse, a considerable effort must be spent transforming an object-oriented representation of the data to a relational one, and vice versa. Fortunately, several good object-relational mappers exist to ease this burden. In this recipe, we explored Hibernate�one of the most popular open source object-relational mappers available to Java programmers.
Hibernate is a very rich product with many unexplored features left for you to discover. Our simple example is limited to read behavior, but the rest of the CRUD family is just as easy. Update functionality is as simple as accessing the desired element, calling the desired JavaBean setter, and calling the session commit method. Hibernate takes care of generating the SQL and updating the table. A delete is also rather simple�session.delete(element) is all it takes! Finally, create only requires instantiating the object, calling the setters, and calling session.save(element).
Hibernate best practices recommend caching the Hibernate factory object. We chose to create and cache the factory using a Struts plug-in. Alternatively, you could have chosen to cache using any other means in your arsenal.
Although this recipe can serve you well, there are some drawbacks. First, we have exposed Hibernate to the Struts Action. Migrating to another persistence layer framework requires us to change every Action employing Hibernate. Second, our persistence is tightly coupled to the presentation layer. This coupling denies us the opportunity to reuse the persistence logic in some other presentation mechanism, such as a batch program.
Although there is room for improvement, this recipe is suitable when you do not expect to reuse your persistence logic."
Monday, January 24, 2005
Subscribe to:
Post Comments (Atom)
Popular Posts
- AS400 Job Scheduler
- Recover or reset QSECOFR passwords
- Make a Home made, open source mp3 Player
- A free fully functional database is yours with Microsoft's SQL Server Express
- AS400 Jobs: Do you have a job at the moment?
- Sending and receiving email on i5/os - QtmmSendMail
- 3 fires up high-speed Super 3G network, News at CNET.co.uk
- AS400 API - QCMDEXC - Execute Command
- API Example - Deleting Old Spooled Files
- UDATE and *DATE in AS400 RPG
No comments:
Post a Comment