[Beginners Corner] - Could not find datasource: jdbc/jndi-name
by jhannoy
Hi,
I'm new to JBoss and facing this problem presently.
I've created a simple EJB3/JPA app and using jboss-4.2.2.GA and Derby embedded. Here is what I have in the following files:
persistence.xml:
| <?xml version="1.0" encoding="UTF-8"?>
| <persistence version="1.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_1_0.xsd">
|
|
| <persistence-unit name="Monitor">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>jdbc/jndi-name</jta-data-source>
| <mapping-file>/META-INF/orm.xml</mapping-file>
|
|
| <properties>
| <property name="hibernate.show_sql" value="true" />
| <property name="hibernate.format_sql" value="true" />
|
| <property name="hibernate.dialect"
| value="org.hibernate.dialect.DerbyDialect" />
| <property name="hibernate.hbm2ddl.auto" value="create" />
| </properties>
|
| </persistence-unit>
| </persistence>
|
I have the following TestClient
|
| package testcases;
|
| import java.util.Properties;
|
| import javax.naming.InitialContext;
|
| import session.Monitor;
|
|
| public class TestClient {
|
| Monitor bean = null;
|
| public void runTest() throws Exception {
| InitialContext ctx = new InitialContext();
| bean = (Monitor) ctx.lookup("OSMonitorSateless/remote");
|
| System.out.println("Searching ejb/OSMonitorSateless...");
|
| <some other initialization code goes here.....
| ..........................
| .............................................>
|
| System.out.println("Creating ejb/OSMonitorSateless...");
| bean.create(snmp.getId(), o, c, i, m, s, snmp.getIn(), snmp.getR(),
| snmp.getB());
| bean.toString();
| }
|
| public static void main(String[] args) {
| try {
| TestClient cli = new TestClient();
| System.out.println("Created Class...");
| cli.runTest();
|
| } catch (Exception e) {
| e.printStackTrace();
| }
| }
|
| }
|
Now whenever I try to run the example, I get the following error:
| - Could not find datasource: jdbc/jndi-name
| 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:52)
| at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
| at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
| at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
| at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
| at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
| at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
| at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
| at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
| at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
| at testcases.EntityManagerBasedTest.initEmfAndEm(EntityManagerBasedTest.java:46)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
| at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
| at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
| at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
| at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
| at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
| at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
| at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
| at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
| at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
| at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
| at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
| 0 [main] FATAL org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: jdbc/jndi-name
| 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:52)
| at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
| at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
| at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
| at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
| at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
| at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
| at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
| at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
| at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
| at testcases.EntityManagerBasedTest.initEmfAndEm(EntityManagerBasedTest.java:46)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
| at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
| at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
| at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
| at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
| at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
| at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
| at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
| at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
| at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
| at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
| at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
|
I have also defined the derby-ds.xml, and it looks like the following:
| <?xml version="1.0" encoding="UTF-8"?>
|
| <datasources>
| <local-tx-datasource>
| <jndi-name>jndi-name</jndi-name>
| <use-java-context>false</use-java-context>
| <connection-url>
| jdbc:derby:C:/JPATest/dataDB
| </connection-url>
| <driver-class>
| org.apache.derby.jdbc.EmbeddedDriver
| </driver-class>
| <user-name>xyzzz</user-name>
| <password>xyzzz</password>
| <exception-sorter-class-name>
| org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
| </exception-sorter-class-name>
| </local-tx-datasource>
| </datasources>
|
Do I need to add need some more xml files in the project?
Will appreciate a lot if somebody can help.
-Thanks,
James.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115239#4115239
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115239
18 years, 3 months
[EJB 3.0] - How to implement a "global" app counter?
by sagimann
Hello,
I'm using JBoss 4.2.2, and I have the following challenge: I have an entity that keeps track of a "global" numeric value for my application, inside the db. I need a session been that should be able to:
1. init the counter to 0
2. update it atomically, i.e when I call some 'getNext' method, it will return the next number and increment the counter in one go.
Something like:
| @PersistenceContext EntityManager em;
|
| void init() {
| // internally, MyCounter's ID field is always 1. I just set the counter value to 0:
| em.persist(new MyCounter(0));
| }
|
| Long getNext() {
| // this is the challenge....
| }
|
My question is: how do I implement such a thing in a cluster-aware application? In a non-clustered environment, I would consider creating a separate persistence unit just for this entity, which will use a db pool that serializes transactions (highest isolation level). Since the transaction is very short relative to transactions in the "normal" PU, it should have little effect on performance.
This would simply require me to set the PU name on the session bean's 'em' member, e.g.:
| @PersistenceContext(name="serializedPU")
| EntityManager em;
|
BUT: in a clustered environment, each appserver would have its own db pool, there is no sync between them... I was thinking of a few options to resolve this:
1. configure all appservers in the cluster to reference a specific appserver for this specific bean, but this would create a single point of failure...
2. Instead of using a separate PU, I could configure the session bean's pool size to max=1, and again, configure all appservers in the cluster to use this bean only on one specific appserver. And again: single point of failure...
3. do something at the dbms level, but this will require knowledge of dbms-specific technicalities, make my application's deployment a lot more complex, etc.
Any better/other suggestions, please?
thanks...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115227#4115227
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115227
18 years, 3 months
[EJB/JBoss] - How to implement a "global" app counter?
by sagimann
Hello,
First, although I'm trying to do this using EJB 3.0, the answer to this question may not be related specifically to EJB 3.0, so I'm posting it here.
I'm using JBoss 4.2.2, and I have the following challenge: I have an entity that keeps track of a "global" numeric value for my application, inside the db. I need a session been that should be able to:
1. init the counter to 0
2. update it atomically, i.e when I call some 'getNext' method, it will return the next number and increment the counter in one go.
Something like:
| @PersistenceContext EntityManager em;
|
| void init() {
| // internally, MyCounter's ID field is always 1. I just set the counter value to 0:
| em.persist(new MyCounter(0));
| }
|
| Long getNext() {
| // this is the challenge....
| }
|
My question is: how do I implement such a thing in a cluster-aware application? In a non-clustered environment, I would consider creating a separate persistence unit just for this entity, which will use a db pool that serializes transactions (highest isolation level). Since the transaction is very short relative to transactions in the "normal" PU, it should have little effect on performance.
This would simply require me to set the PU name on the session bean's 'em' member, e.g.:
| @PersistenceContext(name="serializedPU")
| EntityManager em;
|
BUT: in a clustered environment, each appserver would have its own db pool, there is no sync between them... I was thinking of a few options to resolve this:
1. configure all appservers in the cluster to reference a specific appserver for this specific bean, but this would create a single point of failure...
2. Instead of using a separate PU, I could configure the session bean's pool size to max=1, and again, configure all appservers in the cluster to use this bean only on one specific appserver. And again: single point of failure...
3. do something at the dbms level, but this will require knowledge of dbms-specific technicalities, make my application's deployment a lot more complex, etc.
Any better/other suggestions, please?
thanks...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115226#4115226
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115226
18 years, 3 months