CHAPTER 2 Starting a project Session session = (Business web site)

CHAPTER 2 Starting a project Session session = (Session) entityManager.getDelegate(); Or you can get a Session injected into an EJB component (although this only works in the JBoss Application Server): @Stateless public class MessageHandlerBean implements MessageHandler { @PersistenceContext Session session; … } In rare cases, you can fall back to plain JDBC interfaces from the Hibernate Session: Connection jdbcConnection = session.connection(); This last option comes with some caveats: You aren t allowed to close the JDBC Connection you get from Hibernate this happens automatically. The exception to this rule is that in an environment that relies on aggressive connection releases, which means in a JTA or CMT environment, you have to close the returned connection in application code. A better and safer way to access a JDBC connection directly is through resource injection in a Java EE 5.0. Annotate a field or setter method in an EJB, an EJB lis tener, a servlet, a servlet filter, or even a JavaServer Faces backing bean, like this: @Resource(mappedName=”java:/HelloWorldDS”) DataSource ds; So far, we ve assumed that you work on a new Hibernate or JPA project that involves no legacy application code or existing database schema. We now switch perspectives and consider a development process that is bottom-up. In such a scenario, you probably want to automatically reverse-engineer artifacts from an existing database schema. 2.3 Reverse engineering a legacy database Your first step when mapping a legacy database likely involves an automatic reverse-engineering procedure. After all, an entity schema already exists in your database system. To make this easier, Hibernate has a set of tools that can read a schema and produce various artifacts from this metadata, including XML mapping files and Java source code. All of this is template-based, so many customizations are possible. You can control the reverse-engineering process with tools and tasks in your Ant build. The HibernateToolTask you used earlier to export SQL DDL from
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.