Bonjour!
J'ai un problème avec Hibernate 5 et je ne trouve aucune réponse parlante sur le net, j'ai l'exception suivante:
Quote:
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: PodiumDo is not mapped [FROM PodiumDo where id = :id]
Vous avez une idée?
pom:
Code:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.9.Final</version>
</dependency>
conf:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">pwd</property>
<property name="hibernate.connection.url">jdbc:mysql://host:port/db</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="show_sql">true</property>
<property name="connection.pool_size">1</property>
<mapping class="fr.neio.swagdium.beans.PodiumDo"></mapping>
<mapping class="fr.neio.swagdium.beans.ItemDo"></mapping>
</session-factory>
</hibernate-configuration>
Le bean:
Code:
package fr.neio.swagdium.beans;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "podium")
public class PodiumDo{
@Id
@Column(name = "id")
private Integer id;
@Column(name = "name")
private String name;
//getters/setters
}
hibernate util:
Code:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
private static final ServiceRegistry serviceRegistry;
static {
Configuration conf = new Configuration();
conf.configure("/fr/neio/swagdium/resources/hibernate.cfg.xml");
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build();
try {
sessionFactory = conf.buildSessionFactory(serviceRegistry);
} catch (Exception e) {
System.err.println("Initial SessionFactory creation failed." + e);
throw new ExceptionInInitializerError(e);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Et l'appel:
Code:
session = getSessionFactory().openSession();
tx = session.beginTransaction();
Query<PodiumDo> query = session.createQuery("FROM PodiumDo where id = :id",PodiumDo.class).setParameter(":id", podiumId);
List<PodiumDo> podiums = query.list();
if(podiums != null && !podiums.isEmpty()){
podium = podiums.get(0);
}
tx.commit();
Merci d'avoir lu et pour votre possible réponse!