Skip navigation

Working with JBoss 4.2, Ant and mixing EJB 3 with EJB 2,using different packages to deploy, follwing error occured:

 

--- MBeans waiting for other MBeans ---

ObjectName: persistence.units:unitName=UEPersistanceUnit

  State: FAILED

  Reason: javax.persistence.PersistenceException: [PersistenceUnit: UEPersistanceUnit] class or package not found

  I Depend On:

    jboss.jca:service=DataSourceBinding,name=OraDS

 

--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---

ObjectName: persistence.units:unitName=UEPersistanceUnit

  State: FAILED

  Reason: javax.persistence.PersistenceException: [PersistenceUnit: UEPersistanceUnit] class or package not found

  I Depend On:

    jboss.jca:service=DataSourceBinding,name=OraDS

 

The error message, which appears at the end of the log is misleading.

The only reason was I did mistake my <javac ... in Ant (with <include ... and <exclude...). Some classes where missing in my jar file.

I found that by looking higher in the log and looking into the jar file, where I saw missing files.

I have found a nice Jboss 7.1 and EJB 3 Tutorial/Example under

http://theopentutorials.com/examples/java-ee/ejb3/how-to-create-a-simple-ejb3-project-in-eclipse-jboss-7-1/

 

I have created a diagram to understand the example.

 

HelloWorldSessionBean.JPG

 

Rar-archive from my workspace for that example is attached.

Have fun.

  1. Download the Postgres Driver which you need as .jar-file (http://jdbc.postgresql.org/download.html)
  2. Go to JBoss directory and find modules\org folder. Create two new folders, so you get modules\org\postgresql\main and insert the .jar file there.
  3. Create in the same folder a file named module.xml with the content (set in <resource-root path="" > the name of your .jar-file):
    <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.0" name="org.postgresql">
     <resources>
     <resource-root path="postgresql-Y.X-Z.jdbcV.jar"/>
     </resources>
     <dependencies>
     <module name="javax.api"/>
     <module name="javax.transaction.api"/>
     </dependencies>
    </module>
    
  4. Edit your standalone.xml and add the following code between the tags <datasources><drivers>
     <driver name=”postgresql” module=”org.postgresql”>
     <xa-datasource-class>
     org.postgresql.xa.PGXADataSource
     </xa-datasource-class>
     </driver>
    
  5. Now start the server and check wether he is loading the driver. The console should show something like: INFO [org.jboss.as.connector.subsystems.datasources] JBAS010404: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 8.4). If it nothing showing about your Postgres Driver, check the spelling and the coding (e.g. the quotation marks can be in different code and dont work, can happen if you just copy and paste). Fix this before going on.
  6. Go to your standalone.xml and set between <datasources> following code (set your connection-url, usename and password, jndi-name can also be java:/postgresDS, you can do this step through admin console of the server as well):
    <datasource jndi-name="java:jboss/postgresDS" pool-name="postgresDS" enabled="true" jta="false" use-java-context="true" use-ccm="false">
    <connection-url>
     jdbc:postgresql://192.z.y.x:5432/yourdatabase
     </connection-url>
     <driver-class>
     org.postgresql.Driver
     </driver-class>
     <driver>
     postgresql
     </driver>
     <pool>
     <min-pool-size>
     2
     </min-pool-size>
     <max-pool-size>
     20
     </max-pool-size>
     </pool>
     <security>
     <user-name>
    urusername
     </user-name>
     <password>
    urpasswort
     </password>
     </security>
     <validation>
     <validate-on-match>
     false
     </validate-on-match>
     <background-validation>
     false
     </background-validation>
     <background-validation-millis>
     0
     </background-validation-millis>
     </validation>
     <statement>
     <prepared-statement-cache-size>
     0
     </prepared-statement-cache-size>
     <share-prepared-statements>
     false
     </share-prepared-statements>
     </statement>
     </datasource>
    
    
    
  7. Start you database server
  8. Test the jdbc connection with following jsp-file (set the name of your table and the column names):
    <%@page
     import="java.util.*,javax.naming.*,javax.sql.DataSource,java.sql.*"%>
    <%
     DataSource ds = null;
     Connection con = null;
     Statement stmt = null;
     InitialContext ic;
      
     try {
     ic = new InitialContext();
     ds = (DataSource) ic.lookup("java:/postgresDS");
     con = ds.getConnection();
     stmt = con.createStatement();
     ResultSet rs = stmt.executeQuery("select * from tabname");
    
     while (rs.next()) {
     out.println("<br> " + rs.getString("onecolumn") + " | "
     + rs.getString("othercolumn"));
     }
     rs.close();
     stmt.close();
     } catch (Exception e) {
     out.println("Exception thrown :/");
     e.printStackTrace();
     } finally {
     if (con != null) {
     con.close();
     }
     }
        %>
    
  9. Done.

 

The knowledge for this tutorial i got from the following sites (big thank to them!):

https://community.jboss.org/wiki/JBossAS7-DatasourceConfigurationForPostgresql 

https://community.jboss.org/thread/168958 

http://kousikraj.wordpress.com/2011/11/25/datasource-configuration-setup-for-jboss-as-7-with-example-of-postgresql/ 

http://blog.xebia.com/2011/07/19/developing-a-jpa-application-on-jboss-as-7/ 

http://jan.zawodny.pl/blog/2011/07/jboss-7-postgresql-9 

https://community.jboss.org/thread/168644

Filter Blog

By date:
By tag: