Migrating from Hibernate entitymanager 3.6.9 to 4.1.2 failed mysql connection

I understand that there are reports of porting from 3.x to 4.x.

However, I cannot decrypt and match what these guides say, what I need to do with my maven dependencies or my code.

In particular, the operation ended after

TypedQuery q = em.createQuery (blah ..);

in

List result = q.getResultList ();

When the driver tries to get a connection, ending with croaking

No suitable driver found ...

I could not find direct answers about whether I need

  • make changes to persistence.xml
  • make changes to my code
  • rebuild my jpa paradigm

Are there any changes in my code and my maven dependencies? Do I even have to work hard to get used to hibernation 4?

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> <persistence-unit name="z666" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>z666.Node</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" /> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.connection.username" value="zzz" /> <property name="hibernate.connection.password" value="666" /> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/z666" /> <property name="hibernate.max_fetch_depth" value="3" /> </properties> </persistence-unit> </persistence> 
-1
source share
1 answer

It looks like you are missing the MySQL driver mysql-connector-java-<version>.jar The current version of mysql-connector-java-5.1.20.jar . You need a maven dependency, for example:

 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.20</version> </dependency> 

I don’t know which versions are valid for Hibernate 4, but I think you need at least 5.1

0
source

Source: https://habr.com/ru/post/917430/


All Articles