Hello, yes I find this comments very useful!
karaf@root> ls | grep -B 4 javax.sql.DataSource org.apache.aries.jpa.container.context.PersistenceContextProvider weather-datasource (123) provides: ---------------------------------- javax.sql.DataSource karaf@root> ls 123 weather-datasource (123) provides: ---------------------------------- objectClass = javax.sql.DataSource osgi.jndi.service.name = jdbc/mysqlds osgi.service.blueprint.compname = weatherDataSource service.id = 222 ---- objectClass = org.osgi.service.blueprint.container.BlueprintContainer osgi.blueprint.container.symbolicname = weather-datasource osgi.blueprint.container.version = 1.0.5.SNAPSHOT service.id = 223 I guess the datasource service is published correctly. Thanks, borut Dne 26. april 2012 11:09 je Bengt Rodehav <[email protected]> napisal/-a: > Hello there, > > I guess you should check that your datasource has been published as a > service. I'm not the best Karaf guru but I would do something like this: > > Check what services provides datasources: > > *ls | grep -B 4 javax.sql.DataSource* > > This should identify what bundles provide datasources as services. Assume > that one of the bundles had the bundle id 78, you could then look more > closely at that bundles services with the following command: > > *ls 78* > * > * > You will now see the services provided by this bundle and also its service > properties. You should see a line similar to: > > *osgi.jndi.service.name = jdbc/mysqlds* > > Hope that helps, > > /Bengt > > > > 2012/4/26 Borut Bolčina <[email protected]> > >> Hello, >> >> thanks Bengt for your input, I really appreciate you took the time! >> >> My work on this is somehow sporadic, but now I have managed to get the >> Camel route running in Karaf >> >> from("quartz://weather/currentWeatherSlovenia?cron=0+0/1+*+?+*+*") >> .log("Getting weather from: " + sourceUrl) >> .to(sourceUrl) >> .split() >> .tokenizeXML("metData") >> .unmarshal(jaxbDataFormat) >> >> .to("jpa:com.mycompany.weather.entities.WeatherCurrent?persistenceUnit=weather"); >> >> with the exception of saving the data to the database which fails with: >> >> Caused by: <openjpa-2.2.0-r422266:1244990 fatal user error> >> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or >> DataSource class name must be specified in >> the ConnectionDriverName property. Available properties in configuration >> are "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@442ce698". >> at >> org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:72)[125:org.apache.openjpa:2.2.0] >> at >> org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:844)[125:org.apache.openjpa:2.2.0] >> at >> org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:602)[125:org.apache.openjpa:2.2.0] >> at >> org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1510)[125:org.apache.openjpa:2.2.0] >> at >> org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518)[125:org.apache.openjpa:2.2.0] >> .... >> >> My datasource bundle is deployed in OSGi (later the username and password >> will be configurable, that is - outside of the bundle) >> >> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> >> >> <bean id="weatherDataSource" >> class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"> >> <property name="url" >> value="jdbc:mysql:// >> dev.mycompany.com:3306/weather?useUnicode=yes&characterEncoding=UTF-8<http://dev.mycompany.com:3306/weather?useUnicode=yes&characterEncoding=UTF-8>" >> /> >> <property name="user" value="myUsername" /> >> <property name="password" value="myPassword" /> >> </bean> >> >> <service interface="javax.sql.DataSource" ref="weatherDataSource"> >> <service-properties> >> <entry key="osgi.jndi.service.name" value="jdbc/mysqlds" /> >> </service-properties> >> </service> >> </blueprint> >> >> which is used by my model bundle's persistence.xml >> >> <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="weather" transaction-type="JTA"> >> >> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> >> <jta-data-source>osgi:service/javax.sql.DataSource/( >> osgi.jndi.service.name=jdbc/mysqlds)</jta-data-source> >> <class>my.company.weather.entities.WeatherCurrent</class> >> <exclude-unlisted-classes>true</exclude-unlisted-classes> >> </persistence-unit> >> </persistence> >> >> I think the problem is that my model bundle is not seeing the datasource >> service. How do I confirm that or how should my model's MANIFEST look like? >> >> Cheers, >> borut >> >> >> Dne 19. april 2012 20:35 je Bengt Rodehav <[email protected]> napisal/-a: >> >> A few years back Hibernate was my choice. The past two years I have moved >>> to OpenJPA. The main reason is that OpenJPA works much better with OSGi. I >>> did try EclipseLink as well but had OSGi problems. This was a while back >>> and has probably been improved by now. >>> >>> Another reason why I prefer OpenJPA to Hibernate is that the Apache >>> community is so much better - much more open. I'm sure this is a matter of >>> taste but I would not go for Hibernate. >>> >>> That said, OpenJPA also has some classloading issues under OSGi. In >>> normal situations it works though. A final compelling reason to use OpenJPA >>> is that it is much more common choice when using Apache Karaf (I think). >>> It's normally easier to use different Apache projects together since >>> someone else has always done it before. >>> >>> What I don't like is the way JPA uses the persistence.xml. I tend to go >>> with the approach Christian recommended - to put the datasource in a >>> separate bundle. It can then easily be switched. In practice, though, it's >>> hard to actually change database type (not just url) without having to >>> affect the application. >>> >>> First, the JPA implementation is configured in persistence.xml. E g >>> that's where you specify database dialect for OpenJPA. Ideally this would >>> be separated from the persistence.xml and possible to configure (e g with >>> OSGi's config admin). >>> >>> Second, at least when using JPA annotations (which I do), your source >>> code becomes tailored for a certain database type. I often startup with a >>> simple Derby database for testing and then move to SQLServer for >>> production. In that process I often have to change some annotations to make >>> it work in SQLServer. >>> >>> Overall I'm quite content with the OpenJPA+Aries+Karaf combo though. I >>> just wish that Aries could get their release process straightened out soon. >>> >>> /Bengt >>> >>> >>> 2012/4/19 Borut Bolcina <[email protected]> >>> >>>> On 19. apr. 2012, at 16:11, Christian Schneider < >>>> [email protected]> wrote: >>>> >>>> > I guess the suggested way is to not run hibernate :-) For me the fact >>>> that they do not create bundles says that jboss does not care about OSGi in >>>> hibernate. As they now have an OSGi server with JBoss 7 that may change >>>> soon though. >>>> >>>> I just looked at JBoss website and their support is not even in dipers. >>>> See https://issues.jboss.org/browse/JBOSGI-260. >>>> >>>> > I had some good experience with apache openjpa together with apache >>>> aries jpa. Together they solve the classloading problem where the jpa >>>> provider can not see the user classes. I have not built bigger applications >>>> with it though. >>>> >>>> I will try with OpenJPA, but would really like to hear other people's >>>> hibernate stories! >>>> >>>> > >>>> > There is also Eclipselink. With their affiliation to Eclipse they >>>> will surely have an eye on OSGi compatibility. The problem there was that >>>> they did not put their jas into the maven central repo. >>>> > >>>> > So all in all I am not sure what to recommend. Perhaps others already >>>> have experience with some jpa solution in bigger projects? >>>> >>>> Please share some stories to make my decision easier. >>>> >>>> Borut >>>> >>>> > >>>> > Christian >>>> > >>>> > Am 19.04.2012 15:56, schrieb Borut Bolčina: >>>> >> Thanks Christian, >>>> >> >>>> >> I understand now what you were suggesting. The database type >>>> (vendor) will be the same in all environments (mysql), but with different >>>> addresses, engine types, usernames and passwords, which brings another >>>> topic up - configuration (I will probably ask this in days to come). >>>> >> >>>> >> I will be separating datasources, it is just the case that I want a >>>> working solution and then smooth it out. >>>> >> >>>> >> For a begginer it is very hard to get a hibernate mysql combo to >>>> work (mine still does not). There are examples for persistence, but I had >>>> to read a lot until I found that Hibernate does not even has bundles, >>>> therefore tricks has to be performed. >>>> >> >>>> >> Is there "an official Karaf Hibernate Feature"? If not, what is the >>>> suggested way to run Hibernate in Karaf? I am planning to use Hibernate >>>> Search, Solr and Lucene by using Camel components, so I have lots of ground >>>> to cover. >>>> >> >>>> >> Cheers, >>>> >> borut >>>> >> >>>> > >>>> > -- >>>> > Christian Schneider >>>> > http://www.liquid-reality.de >>>> > >>>> > Open Source Architect >>>> > Talend Application Integration Division http://www.talend.com >>>> > >>>> >>> >>> >> >
