title: CDI + JPA + EJB + JTA + JSF --JBoss-Kitchen Example with PostgreSQL?
body: <p>I am trying to learn the new technologies <code>CDI + JPA + EJB + JTA + JSF</code> so, i have downloaded the sample project from <code>JBoss-Community</code>--> jboss-as-kitchensink(from JBoss in my Eclipse juno).</p>
  
  <p>I am Trying to connect the <code>kitchen</code> with my <strong>PostgreSQL</strong> database:<br>
  My database name is : <code>sampledb</code></p>
  
  <p>My <strong>Table(Member)</strong> Structure is : <strong>Database name</strong> :<code>QUICKSTART_DATABASENAME</code></p>
  
  <pre><code>CREATE TABLE member
  (
    id integer, 
    name text,
    email text,
    phone_number numeric
  );
  </code></pre>
  
  <p>I have edited this files in my kitchen Project :</p>
  
  <p><strong>persistence.xml</strong></p>
  
  <pre><code>&lt;persistence version="2.0"
     xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
          http://java.sun.com/xml/ns/persistence
          http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
     &lt;persistence-unit name="primary"&gt;
       &lt;jta-data-source&gt;java:jboss/datasources/PostgreSQLDS&lt;/jta-data-source&gt;
        &lt;properties&gt;
           &lt;!-- Properties for Hibernate --&gt;
            &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
             &lt;property name="hibernate.show_sql" value="true"/&gt;
  
        &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I Added the Dependency in <strong>pom.xml</strong>:</p>
  
  <pre><code>&lt;!-- PostgreSQL Dependency --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;version&gt;9.1-901.jdbc4&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>But i'm getting error: </p>
  
  <pre><code>[INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 5.554s
  [INFO] Finished at: Sat Sep 21 14:01:48 IST 2013
  [INFO] Final Memory: 20M/175M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.jboss.as.plugins:jboss-as-maven-plugin:7.2.Final:deploy (default-cli) on project jboss-as-kitchensink: Deployment f
  ailed and was rolled back. -&gt; [Help 1]
  [ERROR]
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR]
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  C:\Users\mypc\java\workspace\jboss-as-kitchensink&gt;
  </code></pre>
  
  <p>What should i do so that i can run this application with my database to insert the data.</p>
  
  <p>Do i need to change any code in <code>.java</code> files or any <code>.xml</code> file to make it work?</p>
  
  <p><strong>EDITED after Comments:</strong> By <a href="http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/#optional_components" rel="nofollow">Following this link</a>,I have configured my PostgreSQL into JBoss manually 
  by setting up the standalone-full.xml file of JBoss..</p>
  
  <pre><code>    ----///----    &lt;datasources&gt;
                          &lt;datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"&gt;
                              &lt;connection-url&gt;jdbc:h2:mem:test;DB_CLOSE_DELAY=-1&lt;/connection-url&gt;
                              &lt;driver&gt;h2&lt;/driver&gt;
                              &lt;security&gt;
                                  &lt;user-name&gt;sa&lt;/user-name&gt;
                                  &lt;password&gt;sa&lt;/password&gt;
                              &lt;/security&gt;
                          &lt;/datasource&gt;
  
                          &lt;datasource jndi-name="java:jboss/datasources/PostgreSQLDS" pool-name="PostgreSQLpool" enabled="true" use-java-context="true"&gt;
                              &lt;connection-url&gt;jdbc:postgresql://localhost:5432/QUICKSTART_DATABASENAME&lt;/connection-url&gt;
                              &lt;driver&gt;org.postgresql.Driver&lt;/driver&gt;
                              &lt;security&gt;
                                  &lt;user-name&gt;postgres&lt;/user-name&gt;
                                  &lt;password&gt;postgres&lt;/password&gt;
                              &lt;/security&gt;
                          &lt;/datasource&gt;
                          &lt;drivers&gt;
                              &lt;driver name="h2" module="com.h2database.h2"&gt;
                                  &lt;xa-datasource-class&gt;org.h2.jdbcx.JdbcDataSource&lt;/xa-datasource-class&gt;
                              &lt;/driver&gt;
  
                              &lt;driver name="postgresql" module="org.postgresql"&gt;
                                  &lt;xa-datasource-class&gt;org.postgresql.xa.PGXADataSource&lt;/xa-datasource-class&gt;
                              &lt;/driver&gt;
                          &lt;/drivers&gt;
                      &lt;/datasources&gt;
  ----////---
  </code></pre>
  
  <p><strong>Answer :</strong></p>
  
  <p>Install the PostgreSQL driver and use the XML so that u can make it work.</p>
  
  <p>Follow The Steps : (Suggested By <code>@Craig Ringer</code>) is Very HelpFull</p>
  
  <p><a href="http://jdbc.postgresql.org/download.html" rel="nofollow">Download PgJDBC</a>. I'm assuming you're using postgresql-9.2-1003.jdbc4.jar, the current version at time of writing. Adjust any filenames to match if you need a different version.</p>
  
  <p>Now deploy the JDBC driver to JBoss AS 7 by putting it in the deployments folder or using the deploy command in jboss-cli. This will work for most, but not all, purposes.</p>
  
  <p>Alternately, you an define a PostgreSQL JDBC driver module:</p>
  
  <p>Create the path $JBOSS_HOME/modules/org/postgresql/main. The modules/org part should already exist, make directories for the rest.</p>
  
  <p>In $JBOSS_HOME/modules/org/postgresql/main/modules.xml with the following content, changing the resource-root entry for the PgJDBC driver to refer to the driver you wish to use.</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;module xmlns="urn:jboss:module:1.1" name="org.postgresql"&gt;
           &lt;resources&gt;
               &lt;resource-root path="postgresql-9.2-1003.jdbc4.jar"/&gt;
           &lt;/resources&gt;
           &lt;dependencies&gt;
               &lt;module name="javax.api"/&gt;
               &lt;module name="javax.transaction.api"/&gt;
               &lt;module name="javax.servlet.api" optional="true"/&gt;
           &lt;/dependencies&gt;
       &lt;/module&gt;
  
  Into the same directory as modules.xml place postgresql-9.2-1003.jdbc4.jar
  Open jboss-cli by running $JBOSS_HOME/bin/jboss-cli --connect
  </code></pre>
  
  <p>Run the command:</p>
  
  <pre><code>/subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver, driver-class-name=org.postgresql.Driver, driver-module-name=org.postgresql)
  </code></pre>
  
  <p>Now create any required data sources, etc, using postgresql-driver as the driver name.</p>
  
  <p>You can create a datasource via the web ui, with jboss-cli with the data-source create command (see data-source --help, data-source add --help), or by deploying a -ds.xml file like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;datasources&gt;
    &lt;datasource jndi-name="java:/datasources/PostgresqlDS" enabled="true" use-java-context="true"  
          pool-name="PostgresqlDS"&gt;
      &lt;connection-url&gt;jdbc:postgresql:dbname&lt;/connection-url&gt;
      &lt;driver&gt;postgresql-driver&lt;/driver&gt;
      &lt;security&gt;
        &lt;user-name&gt;username&lt;/user-name&gt;
        &lt;password&gt;password&lt;/password&gt;
      &lt;/security&gt;
    &lt;/datasource&gt;
  &lt;/datasources&gt;
  </code></pre>
  
  <p>For KitchenSink Example: I Tried With These, It Worked till Connection and All the Things.Still It Should be updated After Later...</p>
  
  <p><a href="http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/#optional_components" rel="nofollow">Follow this link</a> Till Creating a database and a user &amp; continue the rest from here !
  Change Persistance To :
  <strong>persitance.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
          http://java.sun.com/xml/ns/persistence
          http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
     &lt;persistence-unit name="primary"&gt;
        &lt;jta-data-source&gt;java:jboss/datasources/KitchenQuickStartDS&lt;/jta-data-source&gt;
        &lt;properties&gt;
           &lt;!-- Properties for Hibernate --&gt;
           &lt;property name="hibernate.show_sql" value="true" /&gt;
        &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>test-persistance.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0"
     xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
          http://java.sun.com/xml/ns/persistence
          http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
     &lt;persistence-unit name="primary"&gt;
        &lt;jta-data-source&gt;java:jboss/datasources/KitchensinkQuickstartTestDS&lt;/jta-data-source&gt;
        &lt;properties&gt;
           &lt;!-- Properties for Hibernate --&gt;
           &lt;property name="hibernate.hbm2ddl.auto" value="create-drop" /&gt;
           &lt;property name="hibernate.show_sql" value="false" /&gt;
        &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>test-ds.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;datasources xmlns="http://www.jboss.org/ironjacamar/schema"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd"&gt;
      &lt;datasource jndi-name="java:jboss/datasources/KitchenQuickStartTestDS"
          pool-name="KitchenQuickStartTestDS" enabled="true"
          use-java-context="true"&gt;
        &lt;connection-url&gt;jdbc:postgresql://localhost:5432/QUICKSTART_DATABASENAME&lt;/connection-url&gt;
          &lt;driver&gt;postgresql-driver&lt;/driver&gt;
          &lt;security&gt;
              &lt;user-name&gt;username&lt;/user-name&gt;
              &lt;password&gt;password&lt;/password&gt;
          &lt;/security&gt;
     &lt;/datasource&gt;
  &lt;/datasources&gt;
  </code></pre>
  
  <p><strong>kitchensink-quickstart-ds.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;datasources xmlns="http://www.jboss.org/ironjacamar/schema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd"&gt;
      &lt;!-- The datasource is bound into JNDI at this location. We reference 
          this in META-INF/persistence.xml --&gt;
      &lt;datasource jndi-name="java:jboss/datasources/KitchenQuickStartDS"
          pool-name="KitchenQuickStartDS" enabled="true"
          use-java-context="true"&gt;
          &lt;connection-url&gt;jdbc:postgresql://localhost:5432/QUICKSTART_DATABASENAME&lt;/connection-url&gt;
          &lt;driver&gt;postgresql-driver&lt;/driver&gt;
          &lt;security&gt;
              &lt;user-name&gt;username&lt;/user-name&gt;
              &lt;password&gt;password&lt;/password&gt;
          &lt;/security&gt;
      &lt;/datasource&gt;
  &lt;/datasources&gt;
  </code></pre>
  
  <p><strong>But Where i'm Stuck is :</strong>
  I'm Unable to insert the Data Inot the Database! It is raising an error as</p>
  
  <pre><code>ERROR: relation "hibernate_sequence" does not exist Position: 17 
  </code></pre>
  
  <p>I need A Help To Configure It .. I tried in <a href="https://www.google.co.in/#q=ERROR%3A+relation+%22hibernate_sequence%22+does+not+exist+Position%3A+17+" rel="nofollow">MANY ways</a></p>