OSGi and Hibernate - not suitable driver - mysql

I got the following situation.
I'm using Apache Felix as OSGi Service implementation and Apache Karaf as OSGi container.
There is a bundle in karaf which should save some data via hibernate into a database, but I always get a SQLException: No Suitable Driver found.
I deployed the mysql-connector-bundle to karaf.
The problem is, in my mind, that hibernate whether imports the mysql-driver-packages nor my classes which should be mapped.
But I don't know hot to fix this. I'm familar to eclipse rcp where the buddy-policy fixes such problems, is there any best practice for this problem for felix and karaf?

What version of hibernate do you use? Only since Hibernate 4, hibernate is aware of OSGi classloaders, and it still doesn't have complete OSGi support. See e.g. https://hibernate.onjira.com/browse/HHH-7527, which is planned for Hibernate 4.2.
We used Gemini JPA with eclipselink instead as JPA provider in OSGi.
In the karaf eco-system, there is Aries JPA, which is primarly used with OpenJPA. See Which JPA providers are supported by Apache Aries Managed JPA?

Hibernate can't access do data and classes from other bundles (at least in version 3.x; I don't know about version 4). It only works easily if all (methods using hibernate, pojos, mapping files, all libraries) is in the same bundle. It can't access resources in other bundles.
Please also see my answer in this thread.

Related

How to exclude the org.json version in MULE 3.9.0 buildpath?

How to exclude the org.json version in MULE 3.9.0 buildpath?
The version is json-20140107 I want to use the latest json version. I tried to exclude in mule-commons but it did not do any help.
The json-20140107.jar library is distributed with Mule 3.9.0. Because of how Mule implements classloading, at execution time classes loaded from that jar file will override a newer version in your application. You must not change the version provided because Mule was tested. Changing any provided library in the distribution can cause unexpected errors.
You could pack a new version of the library and try to use Fine Grain Classloader Control however that seems to be an Enterprise Edition feature not available in the community edition. If you have the Enterprise Edition it is highly recommended to use the last patch version (currently 3.9.4) instead of 3.9.0.
Another solution could be to migrate to Mule 4.x, which uses classloading isolation to avoid this kind of issues. You can use any version of libraries inside applications without conflicting with the provided libraries in the runtime. Again, using the last version available is the recommended way to go. Mule 3 applications are not compatible with Mule 4, so you will need to migrate existing applications.

enable reverse engieneer spring roo 2.0.0.M2

Hi I want to uso Spring roo, but how do I enable database instrospect sentence?
The documentation says that jpa in this roo version is a addon here but after invoke jpa setup --provider --database a springboot example is enable but no applicationContext.xml file is created, and thus I cannot enable reverse engieneer spring roo 2.0.0.M2.
after executing addon suite start --symbolicName org.springframework.roo.wrapping.mysql-connector-java
the database introspect is not enable and this appears Searching 'database introspect' on installed repositories
0 matches found with 'database introspect' on installed repositories
Spring Roo 2.0.0.M2 is the second milestone of Spring Roo 2.0 version. That means that it's not a final release and maybe some features that were available on previous Spring Roo versions could be not complete or could be unavailable on this one.
Here are the differences between the versions names:
GA = General availability (a release); should be very stable and feature complete
RC = Release candidate; probably feature complete and should be pretty stable - problems should be relatively rare and minor, but worth reporting to try to get them fixed for release.
M = Milestone build - probably not feature complete; should be vaguely stable (i.e. it's more than just a nightly snapshot) but may still have problems.
Ansewering your question about database reverse engineer, we are analyzing the posibility to migrate this Spring Roo 1.x feature to Spring Roo 2.x version to be able to use liquibase to mantain the generated model and the related DB using Spring Roo shell. So, maybe this functionality will be available on the next Spring Roo Milestone version or release candidate.
For now, if you want to use database reverse engineer you should try with Spring Roo 2.0.0.M1 (maybe applied changes for that version don't affect to reverse engineer) or with Spring Roo 1.3.2.RELEASE.
Check out the Spring Roo JIRA to know the Spring Roo roadmap. Feel free to report new issues.
Hope this helps.

Version of Hibernate and MySQL to be used in Eclipse Mars

Can anyone suggest which version of Hibernate and MySQL connector I should be using to run a Hibernate application?
I am using MySQL 5.5 and Eclipse Mars
Usually you would use a build manager in order to simplify your project setup, like Maven. And if you do, you then would go to a Maven repository and check all available versions and you would choose the version you need, for example:
Maven MySQL connector repository
Hibernate Maven repository
If you do so, Maven will take care downloading all the necessary dependencies that you will specify in pom.xml
Even if you don't want to use Maven, you can check Maven repositories to verify all available versions, you would download them and try for yourself if those versions suit your desired setup and needs.

How to use JPA (Java Persistance API) with MySQL?

I know how to use JPA with Oracle and derby DBMSs, but is it possible to use MySQL DBMS with the Java Persistence API ? If so, how ?
You may use heavyweight J2EE servers, Jetty/Tomcat servlet engines or standalone Java apps to run JPA stack. Should not matter which jdbc driver being used.
I always use MariaDB(read: MySQL) in my ScopedEntityManager project fine, also have installed on IBM-WAS web server using MSSQL jdbc driver. Download MariaDB Connector/J and MySQL Connector/J packages. You may put both jdbc files to a same application and use connection string to identify which one of the driver use.
jdbc:mysql://localhost:3306/mydbname?useUnicode=true&characterEncoding=utf8
Like most JPA implementations, using the proper JDBC adapter. What's your JPA implementation? EclipseLink?
Edit: You need to have access to a MySQL database, which is trivial to setup.
Yes, it is possible to use MySQL and Java Persistence API.
JPA is not only restricted to Oracle or derby. For example, Netbeans 8 let you use JPA with MySQL. It has everything built in for that functionality such as the MySQL JDBC connector and a JPA implementation called EclipseLink.
If you want to test it yourself, take a look at this tutorial. Although it is referring to derby DBMS, the steps are similiar for MySQL.

Deploying a standalone java application with hsqldb

I have a Java application that uses a local mysql db. I want to give this to clients so they can install it in their machines without installing mysql. I did some research online and many people suggest using HSQLDB. My question is can I use HSQLDB with hibernate? Do I just need HSQLDB and hibernate or do I need Spring as well?
Yes, you can use HSQLDB with Hibernate with or without using the Spring Framework.