Posts

Hibernate unit of work

 Unit of work First, let's define a unit of work. A unit of work is a design pattern described by Martin Fowler as “[maintaining] a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems. ”[ PoEAA ] In other words, its a series of operations we wish to carry out against the database together. Basically, it is a transaction, though fulfilling a unit of work will often span multiple physical database transactions. So really we are talking about a more abstract notion of a transaction. The term "business transaction" is also sometimes used in lieu of unit of work. do not open and close a Session for every simple database call in a single thread. The same is true for database transactions. Database calls in an application are made using a planned sequence; they are grouped into atomic units of work. This also means that auto-commit after every single SQL statement is useless in a...

Improving Hibernate's Performance

Connection Pooling:-         Opening a connection to a database is generally much more expensive than executing an SQL statement. A connection pool is used to minimize the number of connections opened between application and database. Much like a library, your application code needs to be strict about returning connections to the pool when complete, for if it does not do so, your application will run out of connections.This problem can be avoided by  always  using a  finally  block to close your connection, as shown throughout this book. Starving a Pool:-          Hibernate supports a variety of connection pooling mechanisms. If you are using an application server, you may wish to use the built-in pool (typically a connection is obtaining using JNDI). If you can't or don't wish to use your application server's built-in connection pool, Hibernate supports several other connection pools c3p0 http...

Send Email from Java program using apache common email

Commons Email aims to provide a API for sending email. It is built on top of the Java Mail API, which it aims to simplify. Some of the mail classes that are provided are as follows: SimpleEmail  - This class is used to send basic text based emails. MultiPartEmail  - This class is used to send multipart messages. This allows a text message with attachments either inline or attached. HtmlEmail  - This class is used to send HTML formatted emails. It has all of the capabilities as MultiPartEmail allowing attachments to be easily added. It also supports embedded images. ImageHtmlEmail  - This class is used to send HTML formatted emails with inline images. It has all of the capabilities as HtmlEmail but transform all image references to inline images. EmailAttachment  - This is a simple container class to allow for easy handling of attachments. It is for use with instances of MultiPartEmail and HtmlEmail. A simple text email ...