Posted in Uncategorized

Hibernate, postgreSQL, jboss-7

When we start a project,  The most-time consuming task is to initialize the environment and setup a new connection (ORM, Database, EJB etc). Today, I will explain how to setup database connection using Hibernate, Java2ee, JBOSS 7, Eclipse Indigo.

Step by step:
1. Install Eclipse 3.7.2 indigo ide for java-ee developer(
2. Install Jboss Tools 3.3 for eclipse indigo (
3. Create a new Dynamic Web project under Jboss Central

Dynamic Web Project

4. Click Modify button to open Project Facet, and the following screen will pop up:

Project Facets

5. Tick JPA to enable database connection via hibernate.Then  Click Ok to save and close the windows.
6. Unfortunately, the configuration screen to build persistence.xml doesn’t function very well, I need to manually modify it.
 Following is the persistence.xml example to connect to postgresql:

<?xml version=”1.0″ encoding=”UTF-8″?>
<persistence version=”2.0″ xmlns=”; xmlns:xsi=”; xsi:schemaLocation=””&gt;
    <persistence-unit name=”nbs_web” transaction-type=”RESOURCE_LOCAL”
            <property name=”javax.persistence.jdbc.url” value=”jdbc:postgresql://localhost:5432/test”/>
            <property name=”javax.persistence.jdbc.user” value=”test”/>
            <property name=”javax.persistence.jdbc.password” value=”test”/>
            <property name=”javax.persistence.jdbc.driver” value=”org.postgresql.Driver”/>
            <property name=”hibernate.dialect” value=”org.hibernate.dialect.PostgreSQLDialect”/>
            <property name=”hibernate.connection.driver_class” value=”org.postgresql.Driver”/>
            <property name=”hibernate.connection.url” value=”jdbc:postgresql://localhost:5432/test”/>
            <property name=”hibernate.default_schema” value=”public”/>
            <property name=”hibernate.connection.username” value=”test”/>
            <property name=”hibernate.connection.password” value=”test”/>
            <property name=”hibernate.show_sql” value=”true”/>
            <property name=”hibernate.format_sql” value=”true”/>


8. Following is the directory structure , where you should put your  persistence.xml and postgresql driver:

9. Database setup is ready. Now we will need to do the java code.