problem with changing the DB through an ejb
Hi Guys, I have an application that fetches data and is supposed to add records to some tables. Data retrieval is okay, but when I try to add information to the DB, I get the following stack trace. [INFO] 12:26:06,828 WARN [GeronimoConnectionEventListener] connectionErrorOccurred called with null [INFO] ERROR 42X05: Table/View 'OPENJPASEQ' does not exist. [INFO] at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) [INFO] at org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(Unknown Source) [INFO] at org.apache.derby.impl.sql.compile.FromBaseTable.bindNonVTITables(Unknown Source) [INFO] at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown Source) [INFO] at org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown Source) [INFO] at org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown Source) [INFO] at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source) [INFO] at org.apache.derby.impl.sql.compile.CursorNode.bind(Unknown Source) [INFO] at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source) [INFO] at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source) [INFO] at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source) [INFO] at org.apache.derby.impl.jdbc.EmbedPreparedStatement.init(Unknown Source) [INFO] at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.init(Unknown Source) [INFO] at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.init(Unknown Source) [INFO] at org.apache.derby.jdbc.Driver30.newEmbedPreparedStatement(Unknown Source) [INFO] at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source) [INFO] at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source) [INFO] at org.tranql.connector.jdbc.ConnectionHandle.prepareStatement(ConnectionHandle.java:231) [INFO] at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:165) [INFO] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.prepareStatement(LoggingConnectionDe corator.java:225) [INFO] at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:163) [INFO] at org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.prepareStatement(Configuring ConnectionDecorator.java:140) [INFO] at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:152) [INFO] at org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:474) [INFO] at org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:454) [INFO] at org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:443) [INFO] at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.getSequence(TableJDBCSeq.java:420) [INFO] at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.setSequence(TableJDBCSeq.java:464) [INFO] at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:324) [INFO] at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:228) [INFO] at org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60) [INFO] at org.apache.openjpa.util.ImplHelper.generateValue(ImplHelper.java:132) [INFO] at org.apache.openjpa.util.ImplHelper.generateFieldValue(ImplHelper.java:116) [INFO] at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignField(JDBCStoreManager.java:557) [INFO] at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:438) [INFO] at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:423) [INFO] at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:541) [INFO] at org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:134) [INFO] at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:474) [INFO] at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2673) [INFO] at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39) [INFO] at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:854) [INFO] at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1914) [INFO] at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1874) [INFO] at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1792) [INFO] at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:514) [INFO] at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:499) [INFO] at org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:400) [INFO] at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:257) [INFO] at
Re: DataSource, JNDI and EJB module ...
DevIn wrote: Hi there, I actually work on a EJB3 module which must access à Connection Pool on a Geronimo 2 server. I've successfully created the data source (BigDB) in the geronimo console but my EJB Deployment is unsucessfull with the folowing error : 19:53:39,207 ERROR [DirectoryHotDeployer] Unable to deploy: Unable to resolve reference NonJtaDataSourceWrapper in gbean default/testEJB/11846084165 04/jar?EJBModule=default/testEJB/1184608416504/jar,J2EEApplication=null,PersistenceUnitModule=ejb.jar,j2eeType=PersistenceUnit,name=game to a gbean ma tching the pattern [?name=BigDB#org.apache.geronimo.connector.outbound.ConnectionFactorySource]due to: No matches for referencePatterns: [?name=BigDB# My persistence.xml is as below : ?xml version=1.0 encoding=UTF-8? persistence 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; version=1.0 persistence-unit name=game transaction-type=RESOURCE_LOCAL provideroracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider/provider !-- jta-data-sourceBigDB/jta-data-source-- non-jta-data-sourcejdbc/BigDB/non-jta-data-source /persistence-unit /persistence The problem seems to be in the JNDI name of the data source, so I've tried in a separated project to establish a simple connection with the JNDI provider of my geronimo server. My code is : Properties properties = new Properties(); properties.put(java.naming.factory.initial, org.openejb.client.RemoteInitialContextFactory); properties.put(java.naming.provider.url, 127.0.0.1:4201); // properties.put(java.naming.security.principal, myuser); // properties.put(java.naming.security.credentials, mypass); Context ic = new InitialContext(properties); System.out.println(ic.getNameInNamespace()); //Object obj = ic.lookup(jdbc/BigDB); and throws the exception : javax.naming.AuthenticationException: Cannot open object output stream to server: ; nested exception is: java.net.SocketException: Software caused connection abort: socket write error at org.openejb.client.JNDIContext.authenticate(JNDIContext.java:196) at org.openejb.client.JNDIContext.getInitialContext(JNDIContext.java:181) at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.init(Unknown Source) at javax.naming.InitialContext.init(Unknown Source) at com.big.util.Test.main(Test.java:24) The JNDI provider doen't seem to be OK Any help or idea will be welcome. Thanks. Have you tried to use ic.lookup(java:comp/env/jdbc/BigDB);? Also, for your persistence.xml, did you specify a dependency on that db pool that you made in Geornimo in the openejb-jar.xml? I also think that you need both jta-data-source and non-jta-data-source. Hope this helps, Viet
Re: how to access dbpool in EAR application
Xh wrote: Hi All, I can successfully connect to my remote bean, retrieve some results etc. But in real situation I need to access a database. In geronimo-application.xml I have: sys:dependencies sys:dependency sys:groupIdconsole.dbpool/sys:groupId sys:artifactIdDataWeaverEARDB2/sys:artifactId /sys:dependency /sys:dependencies but unlike web.xml, geronimo-application.xml does not allow resource-ref element. I can configure web application to access my database, but it's now what I really want ;( My question is, how to add a pool to EAR application? best regards Lukasz Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html. I think if you already have the DB pool deployed in Geronimo, you can just have a dependency on it in your openejb-jar.xml. Hope this helps, Viet Nguyen
how do I deploy a security realm along with an application?
I am trying to deploy a security realm plan along with an application, so that I do not have to separately deploy the plan and application. I have following in my geronimo-application.xml ?xml version=1.0 encoding=UTF-8? application xmlns=http://geronimo.apache.org/xml/ns/j2ee/application-1.2; environment xmlns=http://geronimo.apache.org/xml/ns/deployment-1.2; moduleId groupId${pom.groupId}/groupId artifactId${pom.artifactId}/artifactId version2.0-SNAPSHOT/version typeear/type /moduleId /environment module !-- I think I need a connector, web, ejb, or java tag here specifying something -- alt-ddTimeReportRealm.xml/alt-dd /module /application As I commented in the deployment descriptor above, I do not know what other line I need to write there because in the console, if I just supply the plan it everything works fine. Is this even the right place to put a security realm plan? Any help will be appreciated. Thanks, Viet
Re: ejb 3.0--connecting to a DB
Viet Hung Nguyen wrote: I am deploying my db pool through the admin console. I am using the tranql-connector-1.3.rar found under geronimo-jetty6-jee5-2.0-SNAPSHOT\repository\org\tranql\tranql-connector-ra\1.3. I am still encountering these two problems: 1) The EJB seems to be talking to the DB, but whenever I query it, the data in the DB is erased. 2) In order to have some data in the DB I have added things to it dynamically. So when I fetch the data from the DB after this addition, the resultList is non-empty. However, when I try to view what I have just added by casting one element of the resultant list (that is of type CollectionExchangeRate) to an ExchangeRate object with this line: ExchangeRate rate = (ExchangeRate)ratesList.get(i); I get a ClassCastException. Initially I thought ratesList might be null, but I have ensured that it is not. For problem 1) I have read somewhere that there is a property I can set so that it does not overwrite the existing data in the DB, but I cannot remember what that is. As for problem 2) I am out of ideas. Thanks in advance, Viet Nguyen The property tag fixed the overwriting of the DB problem. Thanks. But I am using JTA, which is disallowing me to call EntityManager.getTransaction(). It will throw an exception if I am using JTA. I just realized that because I wanted to use SQL queries instead, I have to call EntityManager.createNativeQuery(), which takes two parameters (one of which is the type) if I am using a SELECT statement. I did not specify this, which is the cause of the Exception. Thanks David and Jay. --Viet Nguyen
ejb 3.0--connecting to a DB
I am unable to get a handle on a EntityManagerFactory. I have the following configuration using Derby as the DB on Geronimo 2.0: --*persistence.xml *which is in the JAR file under META-INF-- ?xml version=1.0 encoding=UTF-8? persistence xmlns=http://java.sun.com/xml/ns/persistence; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; version=1.0 xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd; persistence-unit name=BankPU transaction-type=JTA descriptionEntity Beans for Bank/description providerorg.apache.openjpa.persistence.PersistenceProviderImpl/provider classorg.apache.geronimo.samples.bank.ejb.Account/class classorg.apache.geronimo.samples.bank.ejb.Customer/class classorg.apache.geronimo.samples.bank.ejb.ExchangeRate/class exclude-unlisted-classes / properties property name=openjpa.ConnectionURL value=jdbc:derby:BankDB / property name=openjpa.ConnectionDriverName value=org.apache.derby.jdbc.EmbeddedDriver / property name=openjpa.ConnectionUserName value=system / property name=openjpa.ConnectionPassword value=manager / property name=openjpa.Log value=DefaultLevel=INFO / property name=openjpa.AutoDetach value=close / property name=openjpa.DetachState value=all / property name=openjpa.DataCache value=false / property name=openjpa.Optimistic value=true / property name=openjpa.Multithreaded value=true / property name=openjpa.TransactionMode value=local / property name=openjpa.NontransactionalRead value=true / property name=openjpa.RestoreState value=all / property name=openjpa.jdbc.SynchronizeMappings value=false / /properties jta-data-sourceBankPool/jta-data-source non-jta-data-sourceNoTxDatasource/non-jta-data-source /persistence-unit /persistence --*web.xml*-- web-app 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/web-app_2_4.xsd; version=2.4 welcome-file-list welcome-file/jsp/index.jsp/welcome-file /welcome-file-list servlet display-nameCustomerServiceServlet/display-name servlet-nameCustomerServiceServlet/servlet-name servlet-classorg.apache.geronimo.samples.bank.web.CustomerServiceServlet/servlet-class /servlet servlet display-nameCommonServiceServlet/display-name servlet-nameCommonServiceServlet/servlet-name servlet-classorg.apache.geronimo.samples.bank.web.CommonServiceServlet/servlet-class /servlet servlet-mapping servlet-nameCustomerServiceServlet/servlet-name url-pattern/customer_info/url-pattern /servlet-mapping servlet-mapping servlet-nameCommonServiceServlet/servlet-name url-pattern/exchange_rates/url-pattern /servlet-mapping persistence-unit-ref persistence-unit-ref-nameBankPU/persistence-unit-ref-name persistence-unit-nameBankPU/persistence-unit-name /persistence-unit-ref /web-app Here is a snippet of code of how I am I trying to access the EMF: @Stateless public class BankManagerFacadeBean { @PersistenceUnit(unitName=BankPU) protected EntityManagerFactory emf; // other stuff public CollectionAccount getAccountInformation(String customerId) { EntityManager em = emf.createEntityManager(); String query = SELECT * FROM Account WHERE customerId=' + customerId + '; CollectionAccount accountBeanList = (CollectionAccount)em.createQuery( query ).getResultList(); em.close(); return accountBeanList; } } However, 'emf' is actually null after I had mapped BankPU to it. Is there something that I am missing? Thanks, Viet Nguyen
Re: ejb 3.0--connecting to a DB
Thanks David, I resolved the PersistenceUnit problem from the hints that you gave me. However, once all of that was resolved I am having problems connecting to the DB I have the following: --BankPool.xml-- connector xmlns=http://geronimo.apache.org/xml/ns/j2ee/connector-1.1; dep:environment xmlns:dep=http://geronimo.apache.org/xml/ns/deployment-1.1; dep:moduleId dep:groupIdconsole.dbpool/dep:groupId dep:artifactIdBankPool/dep:artifactId dep:version1.0/dep:version dep:typerar/dep:type /dep:moduleId dep:dependencies dep:dependency dep:groupIdorg.apache.derby/dep:groupId dep:artifactIdderby/dep:artifactId dep:typejar/dep:type /dep:dependency /dep:dependencies /dep:environment resourceadapter outbound-resourceadapter connection-definition connectionfactory-interfacejavax.sql.DataSource/connectionfactory-interface connectiondefinition-instance nameBankPool/name config-property-setting name=Driverorg.apache.derby.jdbc.EmbeddedDriver/config-property-setting config-property-setting name=UserNameapp/config-property-setting config-property-setting name=ConnectionURLjdbc:derby:BankDB/config-property-setting connectionmanager local-transaction/ single-pool max-size10/max-size min-size0/min-size match-one/ /single-pool /connectionmanager /connectiondefinition-instance /connection-definition /outbound-resourceadapter /resourceadapter /connector --persistence.xml-- ?xml version=1.0 encoding=UTF-8? persistence xmlns=http://java.sun.com/xml/ns/persistence; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; version=1.0 xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd; persistence-unit name=BankPU transaction-type=JTA descriptionEntity Beans for Bank/description providerorg.apache.openjpa.persistence.PersistenceProviderImpl/provider classorg.apache.geronimo.samples.bank.ejb.Account/class classorg.apache.geronimo.samples.bank.ejb.Customer/class classorg.apache.geronimo.samples.bank.ejb.ExchangeRate/class exclude-unlisted-classes / jta-data-sourceBankPool/jta-data-source non-jta-data-sourceNoTxDatasource/non-jta-data-source /persistence-unit /persistence --web.xml-- web-app 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/web-app_2_5.xsd; version=2.5 welcome-file-list welcome-file/jsp/index.jsp/welcome-file /welcome-file-list servlet display-nameCustomerServiceServlet/display-name servlet-nameCustomerServiceServlet/servlet-name servlet-classorg.apache.geronimo.samples.bank.web.CustomerServiceServlet/servlet-class /servlet servlet display-nameCommonServiceServlet/display-name servlet-nameCommonServiceServlet/servlet-name servlet-classorg.apache.geronimo.samples.bank.web.CommonServiceServlet/servlet-class /servlet servlet-mapping servlet-nameCustomerServiceServlet/servlet-name url-pattern/customer_info/url-pattern /servlet-mapping servlet-mapping servlet-nameCommonServiceServlet/servlet-name url-pattern/exchange_rates/url-pattern /servlet-mapping /web-app --geronimo-web.xml-- web-app xmlns=http://geronimo.apache.org/xml/ns/j2ee/web-1.1; xmlns:naming=http://geronimo.apache.org/xml/ns/naming-1.1; dep:environment xmlns:dep=http://geronimo.apache.org/xml/ns/deployment-1.1; dep:moduleId dep:groupIdorg.apache.geronimo.samples/dep:groupId dep:artifactIdBankWeb/dep:artifactId dep:version1.2/dep:version dep:typecar/dep:type /dep:moduleId dep:dependencies dep:dependency dep:groupIdconsole.dbpool/dep:groupId dep:artifactIdBankPool/dep:artifactId dep:version1.0/dep:version dep:typerar/dep:type /dep:dependency dep:dependency dep:groupIdorg.tranql/dep:groupId dep:artifactIdtranql-connector-ra/dep:artifactId dep:version1.3/dep:version dep:typerar/dep:type /dep:dependency /dep:dependencies dep:hidden-classes/ dep:non-overridable-classes/ /dep:environment context-root/Bank/context-root /web-app --WEB-APP snippet-- public
MDB trouble with references
I am trying to get a simple MDB to work using annotations. However, when I deploy it into Geronimo 2.0, I get the following error. This is with the ConnectionFactory and Queue set up in Geronimo already: Error: Unable to distribute order-ear-2.0-SNAPSHOT.ear: Unable to resolve resource reference 'jms/CommonConnectionFactory' (Could not auto-map to resource. Try adding a resource-ref mapping to your Geronimo deployment plan. My deployment plan for the ConnectionFactory and Queues looks like this: connector xmlns=http://geronimo.apache.org/xml/ns/j2ee/connector-1.1; dep:environment xmlns:dep=http://geronimo.apache.org/xml/ns/deployment-1.2; dep:moduleId dep:groupIdorg.apache.geronimo.samples/dep:groupId dep:artifactIdjms-resources/dep:artifactId dep:version1.2/dep:version dep:typerar/dep:type /dep:moduleId dep:dependencies dep:dependency dep:groupIdorg.apache.geronimo.configs/dep:groupId dep:artifactIdactivemq-broker/dep:artifactId dep:typecar/dep:type /dep:dependency /dep:dependencies /dep:environment resourceadapter resourceadapter-instance resourceadapter-nameCommonConnectionFactory/resourceadapter-name config-property-setting name=Passwordgeronimo/config-property-setting config-property-setting name=UserNamegeronimo/config-property-setting nam:workmanager xmlns:nam=http://geronimo.apache.org/xml/ns/naming-1.1; nam:gbean-linkDefaultWorkManager/nam:gbean-link /nam:workmanager /resourceadapter-instance outbound-resourceadapter connection-definition connectionfactory-interfacejavax.jms.QueueConnectionFactory/connectionfactory-interface connectiondefinition-instance nameCommonConnectionFactory/name connectionmanager xa-transaction transaction-caching/ /xa-transaction single-pool match-one/ /single-pool /connectionmanager /connectiondefinition-instance /connection-definition /outbound-resourceadapter /resourceadapter adminobject adminobject-interfacejavax.jms.Queue/adminobject-interface adminobject-classorg.activemq.message.ActiveMQQueue/adminobject-class adminobject-instance message-destination-nameOrderQueue/message-destination-name config-property-setting name=PhysicalNameOrderQueue/config-property-setting /adminobject-instance adminobject-instance message-destination-nameConsignmentQueue/message-destination-name config-property-setting name=PhysicalNameConsignmentQueue/config-property-setting /adminobject-instance /adminobject adminobject adminobject-interfacejavax.jms.Topic/adminobject-interface adminobject-classorg.activemq.message.ActiveMQTopic/adminobject-class /adminobject /connector I have the MDB with the following annotation @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName=destinationType, propertyValue=javax.jms.Queue), @ActivationConfigProperty(propertyName=destination, propertyValue=jms/OrderQueue) }) I have a Servlet with the following annotated Queue and ConnectionFactory: @Resource(mappedName=jms/OrderQueue) private static Queue receivingQueue; @Resource(mappedName=jms/CommonConnectionFactory) private static QueueConnectionFactory factory; I have the geronimo-web.xml file which has the following: resource-ref ref-namejms/CommonConnectionFactory/ref-name resource-linkCommonConnectionFactory/resource-link /resource-ref resource-env-ref ref-namejms/OrderQueue/ref-name admin-object-linkOrderQueue/admin-object-link /resource-env-ref However, I think that these references are unnecessary when the annotations are present. But I am new to EJBs in general so I am not sure. And I also have a web.xml with the following references too resource-ref res-ref-namejms/CommonConnectionFactory/res-ref-name res-typejavax.jms.QueueConnectionFactory/res-type res-authContainer/res-auth res-sharing-scopeShareable/res-sharing-scope /resource-ref message-destination-ref message-destination-ref-namejms/OrderQueue/message-destination-ref-name message-destination-typejavax.jms.Queue/message-destination-type message-destination-usageProduces/message-destination-usage message-destination-linkOrderQueue/message-destination-link /message-destination-ref Am I missing something? I would appreciate any type of feedback. Thanks, Viet Nguyen