Try any solution but still “no persistent classes found for query class”

0

I’m beginner in Hibernate and I’m just trying to fetch some data from my DB via hibernate but I failed and I got this error :

no persistent classes found for query class: from model.ItemClass

I also try some other query with class.getSimpleName() but I failed again.

These are the output I recieved :

Apr 25, 2019 10:05:32 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.4.2.Final}
Apr 25, 2019 10:05:33 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
Apr 25, 2019 10:05:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Apr 25, 2019 10:05:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/shopping]
Apr 25, 2019 10:05:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
Apr 25, 2019 10:05:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Apr 25, 2019 10:05:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 50 (min=1)
Apr 25, 2019 10:05:35 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Apr 25, 2019 10:05:36 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
Apr 25, 2019 10:05:36 PM org.hibernate.hql.internal.QuerySplitter concreteQueries
WARN: HHH000183: no persistent classes found for query class: from model.ItemClass
0

And these are my files :

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/shopping</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.username">root</property>
        <property name="connection.password">avada</property>
        <property name="connection.pool_size">50</property>
        <mapping resource="model/ItemClass.hbm.xml"/>
        <mapping class="model.ItemClass"/>

        <!-- DB schema will be updated if needed -->
        <!-- <property name="hbm2ddl.auto">update</property> -->
    </session-factory>
</hibernate-configuration>

Testt

import model.ItemClass;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.query.Query;
import org.hibernate.service.ServiceRegistry;

import java.util.List;

public class Testt {

    public static void main(String[] args) {

        Configuration configuration = new Configuration().configure("hibernate.cfg.xml");

        StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();

        serviceRegistryBuilder.applySettings(configuration.getProperties());

        ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();

        SessionFactory MySessionFactory = configuration.buildSessionFactory(serviceRegistry);


        try (Session session = MySessionFactory.openSession()) {
            Query query = session.createQuery("from model.ItemClass");
            List<model.ItemClass> itemClasses = query.list();

            System.out.println(itemClasses.size());

        }

    }



}

ItemClass

package model;

import java.sql.Date;
import java.util.Objects;

public class ItemClass {
    private int id;
    private String name;
    private Integer price;
    private String imageUrl;
    private Integer availableAmount;
    private Integer bought;
    private Date publishTime;
    private String author;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public Integer getAvailableAmount() {
        return availableAmount;
    }

    public void setAvailableAmount(Integer availableAmount) {
        this.availableAmount = availableAmount;
    }

    public Integer getBought() {
        return bought;
    }

    public void setBought(Integer bought) {
        this.bought = bought;
    }

    public Date getPublishTime() {
        return publishTime;
    }

    public void setPublishTime(Date publishTime) {
        this.publishTime = publishTime;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ItemClass itemClass = (ItemClass) o;
        return id == itemClass.id &&
                Objects.equals(name, itemClass.name) &&
                Objects.equals(price, itemClass.price) &&
                Objects.equals(imageUrl, itemClass.imageUrl) &&
                Objects.equals(availableAmount, itemClass.availableAmount) &&
                Objects.equals(bought, itemClass.bought) &&
                Objects.equals(publishTime, itemClass.publishTime) &&
                Objects.equals(author, itemClass.author);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, price, imageUrl, availableAmount, bought, publishTime, author);
    }
}

ItemClass.hbm.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

    <class name="model.ItemClass" table="item" schema="shopping">
        <id name="id">
            <column name="id" sql-type="int(11)"/>
        </id>
        <property name="name">
            <column name="name" sql-type="varchar(45)" length="45"/>
        </property>
        <property name="price">
            <column name="price" sql-type="int(11)" not-null="true"/>
        </property>
        <property name="imageUrl">
            <column name="imageURL" sql-type="varchar(45)" length="45" not-null="true"/>
        </property>
        <property name="availableAmount">
            <column name="available_amount" sql-type="int(11)" not-null="true"/>
        </property>
        <property name="bought">
            <column name="bought" sql-type="int(11)" not-null="true"/>
        </property>
        <property name="publishTime">
            <column name="publish_time" sql-type="date" not-null="true"/>
        </property>
        <property name="author">
            <column name="author" sql-type="varchar(45)" length="45"/>
        </property>
    </class>
</hibernate-mapping>

and this is my project’s directory structure:
54

Would you help me plz ?