Ugh..this is quite frustating...8 full days already. I have to come up with a
SSO-->LDAP-->JSF/Ajax-->SEAM-->ESB-->EJB-->JPA-->Database stack which
includes jBPM + Drools by end of January.
Ok..getting back to the real world..at least the server side is running OK and the schema
creation of the BIDDER table is working. It's only the client side that appears to be
giving me problems. My plan is to get this Java Application client working and
successfully inserting records and then change it into a session bean with @Session and
then work on the JSF/SEAM UI front-end.
Ok...given that the server side is working..I'm now just tweaking and playing around
with various combinations within the client application code.
I know that I don't have to create an entity manager in code because this annotated
portion of code should inject me an entity manager binded to my persistent unit,
BiddingTest :
| @PersistenceContext(unitName="BiddingTest")
| private static EntityManager em;
|
True enough, I commented the code creating the EntityManagerFactory and the app still runs
with no error.
I've gotten rid of the 'Unable to find datasource' error. Last time I did my
EJB 2.1, I also had initial hiccup problems but putting in some properties code solved my
problem.
Here's my new BidClient.java :-
|
My jndi.properties file for BidClient.java is in the main folder of the client module as
follows :-
| java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
| java.naming.provider.url=jnp://localhost:1099
| java.naming.factory.url.pkgs=org.jboss.naming.client
| j2ee.clientName=BiddingClient
|
My application.xml file :
| <?xml version="1.0" encoding="UTF-8"?>
|
| <application
xmlns="http://java.sun.com/xml/ns/j2ee"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
|
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
| version="1.4">
|
| <display-name>BiddingTestEAR</display-name>
| <module>
| <ejb>BiddingTest.jar</ejb>
| </module>
| </application>
|
My application-client.xml file :
| <?xml version="1.0" encoding="UTF-8"?>
|
| <application-client
xmlns="http://java.sun.com/xml/ns/j2ee"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
|
http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd"
| version="1.4">
|
| <display-name>OracleXE1_DS</display-name>
|
| </application-client>
|
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>
|
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>
|
And finally my BidClient.java Java Application client program:
|
|
| import javax.persistence.EntityManager;
| import javax.persistence.EntityManagerFactory;
| import javax.persistence.Persistence;
| import javax.persistence.PersistenceContext;
|
| import org.apache.log4j.Level;
| import org.apache.log4j.Logger;
| import org.apache.log4j.ConsoleAppender;
| import org.apache.log4j.SimpleLayout;
|
| import my.com.eperolehan.entities.Bidder;
|
| import javax.rmi.*;
| import javax.sql.DataSource;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
|
| import java.sql.SQLException;
| import java.util.*;
|
|
|
| public class BidClient {
|
|
| private static EntityManagerFactory f;
|
| @PersistenceContext(unitName="BiddingTest")
| private static EntityManager em;
|
|
| public static void main(String[] args) throws NamingException {
|
|
| Logger log = Logger.getLogger(BidClient.class);
| log.setLevel(Level.WARN);
|
| SimpleLayout layout = new SimpleLayout();
| ConsoleAppender appender = new ConsoleAppender(layout);
|
|
| log.addAppender(appender);
|
|
| try {
|
| Properties p = new Properties();
| p.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
| p.put("java.naming.provider.url", "localhost:1099");
|
|
| InitialContext ctx = new InitialContext( );
| DataSource obj = (DataSource) ctx.lookup("java:OracleXE1_DS");
|
|
| log.debug("[BidClient] : creating EntityManagerFactory...");
| //f = Persistence.createEntityManagerFactory("BiddingTest");
| log.debug("[BidClient] : Created.");
| //em = f.createEntityManager();
| log.debug("[BidClient] : Created.");
|
|
| em.getTransaction().begin();
|
|
| try {
| log.debug("[BidClient] : creating a Bidder...");
| Bidder bidder = new Bidder();
|
| bidder.setBidderName("Bidder No 1");
| bidder.setBidSessionId(1);
|
|
| em.persist(bidder);
| em.getTransaction().commit();
| log.debug("[BidClient] : Bidder created and commited.");
|
| } catch (Exception ex) {
| em.getTransaction().rollback();
| }
|
| log.debug("[BidClient] : Bidder person created and persisted
successfully.");
|
| } catch (RuntimeException e) {
|
| e.printStackTrace();
|
| } finally {
|
|
|
| }
|
|
| em.close();
| //f.close();
|
| }
|
|
| }
|
And the console output :-
| Exception in thread "main" javax.naming.NoInitialContextException: Cannot
instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is
java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory ]
| at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
| at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
| at javax.naming.InitialContext.init(InitialContext.java:223)
| at javax.naming.InitialContext.<init>(InitialContext.java:175)
| at BidClient.main(BidClient.java:71)
| Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
| at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
| at java.security.AccessController.doPrivileged(Native Method)
| at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
| at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
| at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
| at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
| at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
| at java.lang.Class.forName0(Native Method)
| at java.lang.Class.forName(Class.java:242)
| at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
| at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
| ... 4 more
|
Oh boy...I sure would like to move on from here...happy new year!
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4199159#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...