Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Hibernate 5 “is not mapped” exception
PostPosted: Sat Apr 15, 2017 12:35 pm 
Newbie

Joined: Sat Apr 15, 2017 12:30 pm
Posts: 3
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!


Top
 Profile  
 
 Post subject: Re: Hibernate 5 “is not mapped” exception
PostPosted: Sat Apr 15, 2017 1:17 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1172
Try adding an explicit entity name:

Code:
@Entity(name = "PodiumDo")
@Table(name = "podium")
public class PodiumDo {
    ...
}

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Hibernate 5 “is not mapped” exception
PostPosted: Sat Apr 15, 2017 1:37 pm 
Newbie

Joined: Sat Apr 15, 2017 12:30 pm
Posts: 3
Thank you for your answer vlad, but it didn't fix the exception :/


Top
 Profile  
 
 Post subject: Re: Hibernate 5 “is not mapped” exception
PostPosted: Sat Apr 15, 2017 3:20 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1172
Also, instead of

Code:
.setParameter(":id", podiumId);


you should have

Code:
.setParameter("id", podiumId);


Otherwis,e I guess it does not scan the entities properly for your project.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Hibernate 5 “is not mapped” exception
PostPosted: Sat Apr 15, 2017 4:47 pm 
Newbie

Joined: Sat Apr 15, 2017 12:30 pm
Posts: 3
Thank you for correcting this mistake too.

I'm pretty sure it don't read my properties file the right way but I've no idea of how to check that.
I've already used the debug mod on the configurator and the connection information, the host and the driver was there, but I couldn't find any classes...

Did you know how to check the configuration file?


Top
 Profile  
 
 Post subject: Re: Hibernate 5 “is not mapped” exception
PostPosted: Sun Apr 16, 2017 1:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1172
You can debug the Hibernate code and see what happens.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.