[Persistence, JBoss/CMP, Hibernate, Database] - Could not find datasource message in client JPA although EAR
by ezanih
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 :
javax.persistence.PersistenceException: [PersistenceUnit: BiddingTest] Unable to build EntityManagerFactory
and
Caused by: org.hibernate.HibernateException: Could not find datasource
and
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:
| [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 :
| <?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 :
| <?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:
|
| 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!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4198398#4198398
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4198398
15 years, 9 months
[JBossWS] - Problem while configuring EJB3 with env_entry
by kiddcheney
Hi,
I wanted to configure EJB 3.0 with env_entry in JBoss 4.2.2GA. My ejb-jar.xml file is as follows:
<?xml version="1.0" encoding="US-ASCII"?>
| <!-- $Rev: 601953 $ $Date: 2007-12-06 17:09:47 -0800 (Thu, 06 Dec 2007) $ -->
|
| <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" metadata-complete="false">
| <enterprise-beans>
| <session>
|
| <ejb-name>HelloWorldBean</ejb-name>
| <ejb-class>ejb.impl.HelloWorldBean</ejb-class>
| <env-entry>
| <env-entry-name>mystring</env-entry-name>
| <env-entry-type>java.lang.String</env-entry-type>
| <env-entry-value>Hello From ejb-jar.xml file !!!</env-entry-value>
| </env-entry>
|
| </session>
| </enterprise-beans>
| </ejb-jar>
|
But I could neither see the env_entry in Jboss JNDI-view nor access that variable in my EJB.
I doubted whether it was the problem of the Jboss's version, so I tried this on Jboss 4.0.5, but got an error-"Failed to create a new SAX parser". I also tried on Jboss 5.0.0, this time I could see the env_entry in Jboss JNDI-view but I could not see the bean associated with the env_entry.
Can someone help me solove this problem?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4198392#4198392
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4198392
15 years, 9 months
[Installation, Configuration & DEPLOYMENT] - Re: building jboss or microkernel question
by PeterJ
As you have already found out, JBoss AS is a project that includes many other open source projects, many of which are other JBoss projects. And as you found out, those other projects are included mainly as binaries in the thirdparty directory.
I think that the closest you will get to what you want is to run this command from thridparty directory:
mvn package -Pdownload-sources
This command will download most of the sources you are interested in. For example, three source jar files appear in thirdparty/jboss/microcontainer/lib. You can unpack those and use those sources.
What I do is modify the source files I want, compile only the files I changed using the existing JAR files in my javac classpath, and then replacing the original class files in the original JAR files with my newly compiled class files. The result is that the JAR file has my updated classes and the rest of the classes are the originals that shipped with the app server. I know this is not ideal, but I have used this process countless times to make modifications to help track down issues.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4198381#4198381
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4198381
15 years, 9 months