Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why Hibernate criteria return empty list if I have data in my table?

I didn't understand why I am getting empty list from criteria, and I have data in my table.

code where I'm getting List:

hibernateSession_destination = HibernateUtilReports.INSTANCE.getSession();

        Criteria criteria = hibernateSession_destination.createCriteria(nr_rec_backup_rule.class);
        List list = criteria.list();
        System.out.println("List length =======  " + list.size()); // prints size = 0

My HibernateUtilReports.java :

public enum HibernateUtilReports {
    INSTANCE;
    public static SessionFactory sessionFactory = null;

private synchronized SessionFactory getSessionFactory(){

    if(sessionFactory == null){
        Configuration config = new Configuration();
        config.addAnnotatedClass(contaque_recording_log.class);
        config.addAnnotatedClass(contaque_servers.class);
        config.configure("reportshibernate.cfg.xml"); // is here any error???

        Properties configProperties = config.getProperties();
        ServiceRegistryBuilder serviceRegisteryBuilder = new ServiceRegistryBuilder();
        ServiceRegistry serviceRegistry = serviceRegisteryBuilder.applySettings(configProperties).buildServiceRegistry();
        sessionFactory = config.buildSessionFactory(serviceRegistry);
    }
    return sessionFactory;
}

public Session getSession(){
    return getSessionFactory().openSession();
}
}

My reportshibernate.cfg.xml:

<?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="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="connection.url">jdbc:oracle:thin:@8080/xe</property> 
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.connection.password">1234</property>

        <property name="c3p0.minPoolSize">2</property>
    <property name="c3p0.maxPoolSize">100</property>
    <property name="c3p0.timeout">1000</property>
    <property name="hibernate.cache.use_second_level_cache">false</property>
    <property name="show_sql">true</property>
    <property name="hibernate.connection.zeroDateTimeBehavior">convertToNull</property>

</session-factory>

Where am I going wrong???

Edited:

Note: Since "show_sql" is set to 'true' in my xml, but I am not getting any SQL query on my console.

like image 332
earthmover Avatar asked Nov 30 '22 00:11

earthmover


1 Answers

For those who are still looking for an answer to this question as I was, Please check your hibernate config xml and make sure your hibernate entity is declared there

like image 87
Mathews Avatar answered May 14 '23 18:05

Mathews