-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Test JPA Client giving error although EAR deployed
PostPosted: Wed Dec 24, 2008 1:01 am 
Newbie

Joined: Mon Mar 31, 2008 12:50 am
Posts: 4
Hi there

I created a very simple JPA Entity Project (BiddingTest) involving one bid entity (Bidder.java) and one bid client (BidClient.java) from the JPA Project Wizard in Eclipse Ganymede and JBoss 4.2.2.GA. I use Hibernate 3.3.1, Hibernate Annotations 3.4 and Hibernate Entity Manager 3.4.

My BiddingTestEAR was built and deployed succesfully by the JBoss Server and I checked in my OracleXE db and found out that it had successfully managed to create the BIDDER table.

However my problem occurs when I try to populate this BIDDER table from a JPA Test Client. The JPA Test Client keeps giving me the exception :

Code:
javax.persistence.PersistenceException: [PersistenceUnit: BiddingTest] Unable to build EntityManagerFactory


and

Code:
Caused by: org.hibernate.HibernateException: Could not find datasource


and

Code:
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
.


Here is my console output:

Code:
[BidClient] : creating EntityManagerFactory...
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
javax.persistence.PersistenceException: [PersistenceUnit: BiddingTest] Unable to build EntityManagerFactory
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
   at Main.main(Main.java:43)
Caused by: org.hibernate.HibernateException: Could not find datasource
   at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
   at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
   ... 4 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
   at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
   at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
   at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
   at javax.naming.InitialContext.lookup(InitialContext.java:351)
   at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
   ... 11 more
[BidClient] : closing entity manager and factory...
Exception in thread "main" java.lang.NullPointerException
   at Main.main(Main.java:88)



This is my persistence.xml file :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence>
   <persistence-unit name="BiddingTest">
      <jta-data-source>java:/OracleXE1_DS</jta-data-source>
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
      </properties>
   </persistence-unit>
</persistence>



This is my oracle-ds.xml file :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
  <local-tx-datasource>
    <jndi-name>OracleXE1_DS</jndi-name>
    <connection-url>jdbc:oracle:thin:system/system@localhost:1521:XE</connection-url>
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <user-name>system</user-name>
    <password>system</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
   <metadata>
      <type-mapping>Oracle10g</type-mapping>
   </metadata>
  </local-tx-datasource>
</datasources>


This is my BidClient.java file:

Code:

package my.com.eperolehan.client;


import javax.persistence.EntityManager;
//import javax.persistence.EntityTransaction;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
//import javax.persistence.PersistenceContext;

import my.com.eperolehan.entities.Bidder;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.SimpleLayout;


public class BidClient {

   
   private static EntityManagerFactory f;
   
   //@PersistenceContext(unitName="BiddingTest")
   private static EntityManager em;

   
   public static void main(String[] args) {

      
      Logger log = Logger.getLogger(BidClient.class);
      log.setLevel(Level.WARN);
      
      SimpleLayout layout = new SimpleLayout();
      ConsoleAppender appender = new ConsoleAppender(layout);

      
      log.addAppender(appender);
      
      
           try {
                 
                 
                 System.out.println("[BidClient] : creating EntityManagerFactory...");
                 log.debug("[BidClient] : creating EntityManagerFactory...");
                 f = Persistence.createEntityManagerFactory("BiddingTest");
                 System.out.println("[BidClient] : Created.");
                 log.debug("[BidClient] : Created.");   
                 System.out.println("[BidClient] : creating EntityManager...");
                 em = f.createEntityManager();
                 System.out.println("[BidClient] : Created.");
                 log.debug("[BidClient] : Created.");

                 
                 em.getTransaction().begin();

                
                 try {
                    System.out.println("[BidClient] : creating a Bidder...");
                    Bidder bidder = new Bidder();

                           bidder.setBidderName("Bidder No 1");
                           bidder.setBidSessionId(1);


                     em.persist(bidder);
                     em.getTransaction().commit();
                     System.out.println("[BidClient] : Bidder created and commited.");
                     log.debug("[BidClient] : Bidder created and commited.");
                    
                 } catch (Exception ex) {
                    em.getTransaction().rollback();
                 }

                 System.out.println("[BidClient] : Bidder person created and persisted successfully.");
                     log.debug("[BidClient] : Bidder person created and persisted successfully.");
          
           } catch (RuntimeException e) {
              
                     e.printStackTrace();
          
           } finally {
              
              
              
           }


           System.out.println("[BidClient] : closing entity manager and factory...");
           log.debug("[BidClient] : closing entity manager and factory...");
           em.close();      
           //f.close();
           System.out.println("[BidClient] : Closed.");
           log.debug("[BidClient] : Closed.");
      
   }
   
   
}


Please can help me. Thank you very much in advance![/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.