-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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: 1628
Location: Romania
Try adding an explicit entity name:

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


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: 1628
Location: Romania
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.


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: 1628
Location: Romania
You can debug the Hibernate code and see what happens.


Top
 Profile  
 
 Post subject: Re: Hibernate 5 “is not mapped” exception
PostPosted: Sat Jul 29, 2017 10:45 pm 
Newbie

Joined: Sat Jul 29, 2017 10:38 pm
Posts: 1
Obviously,the Hibernate doesn't get your entity mapping. so you need specify your entity class in hibernate.cfg.xml.
like this:
<mapping class="mine.practice.hibernate.model.*"/>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.