Re: ejb 3.0--connecting to a DB

2007-06-20 Thread Jay D. McHugh

Viet,

Try setting:

property name=openjpa.jdbc.SynchronizeMappings value=false /

I believe the default setting will rebuild your database and clear your 
tables.


As far as your data persisting, you will need to make sure you start a 
transaction and commit it after changing data.


Since you are using local transactions (in your persistence.xml), try:

em.getTransaction().begin(); // to start the transaction

and

em.getTransaction().commit();  // to close the transaction

I had the same problems when I started using JPA so hopefully that will 
work for you.



Jay
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


.



Re: ejb 3.0--connecting to a DB

2007-06-20 Thread Jay D. McHugh

Viet,

I just looked again at your original email and persistence.xml - you are 
already setting openjpa.jdbc.SynchronizeMappings to false, so hopefully 
your whole problem is just related to transactions.


Jay

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


.



Re: ejb 3.0--connecting to a DB

2007-06-20 Thread Viet Hung Nguyen

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

2007-06-19 Thread Viet Hung Nguyen

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

2007-06-19 Thread David Jencks

I'm a bit confused.

-- the persistence-unit-ref is in a web.xml whereas the annotation  
appears to be in an ejb
-- Since you are supplying datasources,  leave out the connection  
info from the properties
-- your web-app is version 2.4 whereas jpa stuff is only supported in  
2.5 (although I think geronimo won't object to this)



All this being said I'd expect a lot of exceptions in the geronimo  
log from trying to deploy or run this.


I don't see anything that I think would make this fail, so please  
check the logs.


You are using 2.0-M6 or trunk, right?

thanks
david jencks

On Jun 19, 2007, at 4:23 PM, Viet Hung Nguyen wrote:


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

2007-06-19 Thread Viet Hung Nguyen
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 

Re: ejb 3.0--connecting to a DB

2007-06-19 Thread David Jencks


On Jun 19, 2007, at 10:26 PM, Viet Hung Nguyen wrote:

Thanks David, I resolved the PersistenceUnit problem from the hints  
that you gave me.



Excellent!


However, once all of that was resolved I am having problems  
connecting to the DB


It looks like you generated the db pool plan from the console.  I'm  
not an expert on how well the console works, but I think there are  
some questionable things here:


-- In my experience derby connectors don't work very well unless they  
get their classes from the system-database configuration where the  
derby engine is running.  Unless you use non-embedded derby client  
and maybe even then, you tend to run into classloading problems.  So  
I would replace the dependency on derby with a dependency on  
org.apache.geronimo.configs/system-database//car


- Unless you have previously created your database, you need to include
config-property-setting  
name=CreateDatabasetrue/config-property-setting

to get derby to create it for you when you try to use it.

- You haven't got this far yet :-) but the jta and non-jta datasource  
should be pointing to the same database or you will get very strange  
results when openjpa tries to generate  a key.  It's also likely that  
all the tables will be generated in one of the databases and not  
available in the other.


I'm not sure which tranql connector you are using, either.  I would  
copy the system-database plan and remove the gbeans from it and  
change the dependencies so it depends on system-database and change  
the db names.


How are you deploying the db pool?

Hope this helps
david jencks




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-