Will give it a try Thanks Alasdair,
/Bengt 2010/9/18 Alasdair Nottingham <[email protected]> > Great, I guess we were too smart by half :) > > When you are happy with what you have would you be willing to summarise > your experience? I can then use it to add more doc to the website. > > Thanks > Alasdair > > On 18 Sep 2010, at 10:43, Bengt Rodehav <[email protected]> wrote: > > Solved it myself. Looked at the activator and realised it's all taken care > of automatically - very slick! > > Thanks, > > /Bengt > > 2010/9/18 Bengt Rodehav < <[email protected]>[email protected]> > >> Alasdair, >> >> Thanks for the tip. I tried this: >> >> >> <bean id="refdataXADataSourceWrapper" >>> class="org.apache.aries.transaction.jdbc.XADatasourceEnlistingWrapper"> >> >> <property name="dataSource" ref="refdataXADataSource" /> >> >> </bean> >> >> >>> <service ref="refdataXADataSourceWrapper" >>> interface="javax.sql.DataSource"> >> >> <service-properties> >> >> <entry key="osgi.jndi.service.name" value="jdbc/refdatajta" /> >> >> </service-properties> >> >> </service> >> >> >> But it seems like the org.apache.aries.transaction.jdbc package is not >> exported. Obviously I'm doing it the wrong way. Do you have a sample? >> >> Thanks, >> >> /Bengt >> 2010/9/18 Alasdair Nottingham < <[email protected]>[email protected]> >> >> Hi, >>> >>> Since you are using an XA DataSource you need a some transaction support. >>> I'll assume you have a JTA service implementation, but if you grab the >>> transaction/transaction-wrappers project it will adapt your XADataSource >>> into a DataSource. >>> >>> You'll need to change the lookup back to DataSource. >>> >>> Alasdair Nottingham >>> >>> On 18 Sep 2010, at 08:41, Bengt Rodehav < <[email protected]> >>> [email protected]> wrote: >>> >>> Thanks a lot Valentin! >>> >>> You were right about those 2 issues. I now got further but not all the >>> way. The first time I use an entity manager: >>> >>> mEntityManager.persist(theAccount) >>> >>> >>> I get the following exception: >>> >>> Caused by: java.lang.ClassCastException: >>>> $javax.sql.XADataSource$$EnhancerByCGLIB$$755fe697 cannot be cast to >>>> javax.sql.DataSource >>> >>> at >>>> org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource.getDs(DelayedLookupDataSource.java:43) >>> >>> at >>>> org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource.getConnection(DelayedLookupDataSource.java:60) >>> >>> at >>>> org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:137) >>> >>> at >>>> org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:112) >>> >>> at >>>> org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:239) >>> >>> ... 51 more >>> >>> >>> Seems like OpenJPA wants a javax.sql.DataSource but is given something >>> else. The entity manager is injected using Blueprint as follows: >>> >>> <?xml version="1.0" encoding="UTF-8"?> >>> >>> <blueprint xmlns=" >>> <http://www.osgi.org/xmlns/blueprint/v1.0.0><http://www.osgi.org/xmlns/blueprint/v1.0.0> >>>> http://www.osgi.org/xmlns/blueprint/v1.0.0" >>>> xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance><http://www.w3.org/2001/XMLSchema-instance> >>>> http://www.w3.org/2001/XMLSchema-instance" >>> >>> xsi:schemaLocation=" >>> <http://www.osgi.org/xmlns/blueprint/v1.0.0><http://www.osgi.org/xmlns/blueprint/v1.0.0> >>>> http://www.osgi.org/xmlns/blueprint/v1.0.0" >>>> xmlns:tx="<http://aries.apache.org/xmlns/transactions/v1.0.0><http://aries.apache.org/xmlns/transactions/v1.0.0> >>>> http://aries.apache.org/xmlns/transactions/v1.0.0" >>> >>> xmlns:jpa=" >>> <http://aries.apache.org/xmlns/jpa/v1.0.0><http://aries.apache.org/xmlns/jpa/v1.0.0> >>>> http://aries.apache.org/xmlns/jpa/v1.0.0"> >>> >>> >>>> <bean id="accountServiceImpl" >>>> class="se.digia.sts.refdata.impl.AccountServiceImpl"> >>> >>> <tx:transaction method="*" value="Required" /> >>> >>> <jpa:context property="entityManager" unitname="refdataPU" /> >>> >>> </bean> >>> >>> >>>> <service ref="accountServiceImpl" >>>> interface="se.digia.sts.refdata.api.IAccountService"> >>> >>> </service> >>> >>> </blueprint> >>> >>> >>> Any thoughts? >>> >>> /Bengt >>> >>> >>> 2010/9/18 Valentin Mahrwald < >>> <[email protected]><[email protected]> >>> [email protected]> >>> >>>> Hi Bengt, >>>> >>>> the error you see in my experience is almost always due to the >>>> jta-data-source not being found, OpenJPA then goes on to try creating a >>>> data >>>> source from the properties (in the persistence.xml not the ones in >>>> blueprint) where you have nothing specified. >>>> >>>> In your persistence xml I think where you have: >>>> >>>> <jta-data-source>osgi:services/javax.sql.DataSource/(<http://osgi.jndi.service.name/> >>>>> osgi.jndi.service.name=jdbc/refdatajta)</jta-data-source> >>>> >>>> it should be >>>> >>>> <jta-data-source>osgi:service/javax.sql.XADataSource/(<http://osgi.jndi.service.name/> >>>>> osgi.jndi.service.name=jdbc/refdatajta)</jta-data-source> >>>> >>>> >>>> Two things there: >>>> - the url namespace is org:service, not osgi:services >>>> - the interface needs to match what you export in blueprint below where >>>> you have javax.sql.XADataSource rather than just javax.sql.DataSource >>>> >>>> Hope this helps :) >>>> >>>> Valentin >>>> >>>> On 18 Sep 2010, at 11:11, Bengt Rodehav wrote: >>>> >>>> I cannot seem to get OpenJPA and MySQL to work in Aries. I use Aries >>>> 0.2-incubating, OpenJPA 2.0.1 and the 5.1.13 version of MySQL's JDBC >>>> driver. >>>> >>>> I have no problems connecting to MySQL outside of OSGi but cannot get it >>>> to work in OSGi. BTW I mostly use PaxExam for the Aries tests and I run on >>>> Felix 2.0.0. >>>> >>>> My persistence.xml looks as follows: >>>> >>>> <?xml version="1.0" encoding="UTF-8"?> >>>> >>>> <persistence xmlns=" >>>> <http://java.sun.com/xml/ns/persistence><http://java.sun.com/xml/ns/persistence> >>>>> http://java.sun.com/xml/ns/persistence" >>>>> xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance><http://www.w3.org/2001/XMLSchema-instance> >>>>> http://www.w3.org/2001/XMLSchema-instance" >>>> >>>> xsi:schemaLocation=" >>>> <http://java.sun.com/xml/ns/persistence><http://java.sun.com/xml/ns/persistence> >>>>> http://java.sun.com/xml/ns/persistence >>>>> <http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd><http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd> >>>>> http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" >>>> >>>> version="2.0"> >>>> >>>> <persistence-unit name="refdataPU" transaction-type="JTA"> >>>> >>>> >>>>> >>>>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> >>>> >>>> >>>> <jta-data-source>osgi:services/javax.sql.DataSource/(<http://osgi.jndi.service.name/> >>>>> osgi.jndi.service.name=jdbc/refdatajta)</jta-data-source> >>>> >>>> <class>se.digia.sts.refdata.domain.Account</class> >>>> >>>> <class>se.digia.sts.refdata.domain.BusinessUnit</class> >>>> >>>> <class>se.digia.sts.persistence.EntityBase</class> >>>> >>>> <exclude-unlisted-classes>true</exclude-unlisted-classes> >>>> >>>> <properties> >>>> >>>> <property name="openjpa.Connection2URL" >>>>> value="jdbc:mysql://localhost:3306/refdata" /> >>>> >>>> <property name="openjpa.Connection2DriverName" >>>>> value="com.mysql.jdbc.Driver" /> >>>> >>>> <property name="openjpa.Connection2UserName" value="someuser" /> >>>> >>>> <property name="openjpa.Connection2Password" value="somepassword" >>>>> /> >>>> >>>> <property name="openjpa.ConnectionFactoryMode" value="managed" /> >>>> >>>> <property name="openjpa.jdbc.SynchronizeMappings" >>>>> value="buildSchema(ForeignKeys=true)" /> >>>> >>>> <property name="openjpa.jdbc.DBDictionary" >>>>> value="org.apache.openjpa.jdbc.sql.MySQLDictionary" /> >>>> >>>> <property name="openjpa.jdbc.UpdateManager" >>>>> value="operation-order" /> >>>> >>>> <property name="openjpa.Log" value="DefaultLevel=TRACE, Tool=INFO" >>>>> /> >>>> >>>> </properties> >>>> >>>> </persistence-unit> >>>> >>>> </persistence> >>>> >>>> >>>> and the blueprint for my datasource looks as follows: >>>> >>>> <?xml version="1.0" encoding="UTF-8"?> >>>> >>>> <blueprint xmlns=" >>>> <http://www.osgi.org/xmlns/blueprint/v1.0.0><http://www.osgi.org/xmlns/blueprint/v1.0.0> >>>>> http://www.osgi.org/xmlns/blueprint/v1.0.0" >>>>> xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance><http://www.w3.org/2001/XMLSchema-instance> >>>>> http://www.w3.org/2001/XMLSchema-instance" >>>> >>>> xsi:schemaLocation=" >>>> <http://www.osgi.org/xmlns/blueprint/v1.0.0><http://www.osgi.org/xmlns/blueprint/v1.0.0> >>>>> http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy"> >>>> >>>> >>>>> <bean id="refdataXADataSource" >>>>> class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"> >>>> >>>> <property name="user" value="someuser" /> >>>> >>>> <property name="password" value="somepassword" /> >>>> >>>> <property name="URL" value="jdbc:mysql://localhost:3306/refdata" >>>>> /> >>>> >>>> <!-- <property name="driverClassName" value="com.mysql.jdbc.Driver" >>>>> />--> >>>> >>>> <!-- <property name="url" >>>>> value="jdbc:mysql://localhost:3306/refdata" />--> >>>> >>>> </bean> >>>> >>>> >>>>> <service ref="refdataXADataSource" >>>>> interface="javax.sql.XADataSource"> >>>> >>>> <service-properties> >>>> >>>> <entry key=" <http://osgi.jndi.service.name/> >>>>> osgi.jndi.service.name" value="jdbc/refdatajta" /> >>>> >>>> </service-properties> >>>> >>>> </service> >>>> >>>> >>>> >>>> </blueprint> >>>> >>>> >>>> I get the following exception: >>>> >>>> <openjpa-2.0.1-r422266:989424 nonfatal general error> >>>>> org.apache.openjpa.persistence.PersistenceException: There were errors >>>>> initializing your configuration: <openjpa-2.0.1-r422266:989424 fatal user >>>>> error> org.apache.openjpa.util.UserException: A connection could not be >>>>> obtained for driver class "null" and URL "null". You may have specified >>>>> an >>>>> invalid URL. >>>> >>>> at >>>>> org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:261) >>>> >>>> at >>>>> org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:247) >>>> >>>> at >>>>> org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:728) >>>> >>>> >>>> >>>> I've tried numerous ways to configure the MysqlXADataSource to no avail. >>>> Seems like this must be a very common combination which leads me to hope >>>> that someone can help me out. The only samples I've seen in combination >>>> with >>>> Aries uses a Derby database that doesn't seem to need any configuration. >>>> >>>> I don't think there is anything wrong with the actual settings (user, >>>> password, URL) since they work perfectly outside of OSGi. However, the >>>> settings don't seem to get to the data source. I've probably not fully >>>> understood how this works. My next step would be to somehow configure a >>>> connection pool but it seems like just getting things to work occupies most >>>> of time right now. >>>> >>>> Any clues? >>>> >>>> /Bengt >>>> >>>> >>>> >>> >> >
