How to use JPA (Java Persistance API) with MySQL? - 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.

Related

Implementing the mongodb and java connector

i need a connector where the mongodb data should be accessed in java ..Here the problem is the connector should support hibernate or spring.
If it is an opensource it will be more helpful..
Are there any new mongodb connectors which supports the hibernate.
Try this open source which is jpa based and supports seven datastores in additon to mongodb
https://github.com/impetus-opensource/Kundera/wiki
http://recipes4geeks.com/2011/05/02/working-with-mongodb-using-kundera/
https://github.com/impetus-opensource/Kundera/wiki/Getting-Started-in-5-minutes

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.

OSGi and Hibernate - not suitable driver

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.

communicate MATLAB SQL Server

Is there a way to communicate these Platforms effieciently?
I'm saying, something like exporting (SQL Server)and load (Matlab) but in an efficient way?
I've found adodb_tools on File Exchange to work the best so far. It's much faster than the database toolbox or any prior wrapping solutions.
Doesn't require additional toolboxes but in all likelihood will require you're on Windows for the ADO OLEDB ActiveX support.
Use MATLAB's capability to run Java code in order to access any database that provides a JDBC driver. If you mind using Java, buy the Database Toolbox as mentioned by #b3.
As mentioned use Java and the JDBC driver for your chosen database.
If you look through Stackoverflow there are a few posting about connecting MATLAB and MySQL.
MySQL and Matlab
and
How can i remotely connect ODBC using Java in Windows XP?
These solutions should work with a little tweaking for your database driver.

What is the best way to connect to a Mysql database in Delphi

What is the best component to use when connecting to a Mysql 5.1.x in Delphi and why ?
No other DB components could beat DevArt DB Components, they have MyDac and UniDac, both of them could use direct access to the database without requiring mysql client to be installed on the client machine, beside they offer fast performance and high quality compared to other components
Data Access Components for MySQL
Universal Data Access Components
and check the pages above to know why ;-)
You should take a look at AnyDAC, supports MySQL and a lot of other databases.
Devart and microOLAP both offer components to access MySQL databases. Devart also have dbExpress drivers for dbExpress users.
Bob Swart has published Delphi for Win32 VCL Database Development on Lulu, if you need any help.
Don't forget that MySQL's client dll are GPL-ed, and if you are using it to connect to server, your app must be GPL-ed.
There are alternatives. Components that connect directly to MySQL skipping GPLed dlls. DevArt has such components (direct and dbx), and there are free components that can connect directily on tory.net.
I don't use MySQL, but when I can, I prefer dbExpress. It's unidirectional, which makes it pretty fast. Though I haven't done any benchmarking recently.
If dbExpress isn't your thing, I found this list of components for MySQL access.