Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: criteriaQuery().list() returning repeated rows
PostPosted: Mon Jun 04, 2012 9:05 am 
Newbie

Joined: Mon Jun 04, 2012 8:45 am
Posts: 2
I am experiencing a weird thing while using criteriaQuery list method.
It returns me the same 1st row in the database without considering the other rows.

The following is the code snippet:

HibernateUtil Class

package myapp.hibernateUtil;

import myapp.beans.ParamBean;
import myapp.beans.UserBean;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();

private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new AnnotationConfiguration()
.addPackage("myapp.beans")
.addAnnotatedClass(UserBean.class)
.addAnnotatedClass(ParamBean.class)
.configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}

Dao Class:

...
...
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List <ParamBean> paramAttrib = new ArrayList<ParamBean>();
paramAttrib = (List<ParamBean>) session.createCriteria(ParamBean.class).list();
...

The above query returns the same rows in the paramAttrib despite of the fact that there are many distinct rows in the database

Database:

SERVER_UID DATE TIME APP_PARAM APP_PARAM_VALUE
SERVER_UID_1 2012-06-01 00:00:00 1 CPU_UTILIZATION -760
SERVER_UID_1 2012-06-01 00:00:00 2 CPU_UTILIZATION 50
SERVER_UID_1 2012-06-01 00:00:00 3 CPU_UTILIZATION 50
SERVER_UID_1 2012-06-01 00:00:00 4 CPU_UTILIZATION 50
SERVER_UID_1 2012-06-01 00:00:00 5 CPU_UTILIZATION 60
SERVER_UID_1 2012-06-01 00:00:00 6 CPU_UTILIZATION 70
SERVER_UID_1 2012-06-01 00:00:00 7 CPU_UTILIZATION 80
SERVER_UID_1 2012-06-01 00:00:00 8 CPU_UTILIZATION 40
SERVER_UID_1 2012-06-01 00:00:00 9 CPU_UTILIZATION 10
SERVER_UID_1 2012-06-01 00:00:00 10 CPU_UTILIZATION 70
SERVER_UID_1 2012-06-01 00:00:00 11 CPU_UTILIZATION 384
SERVER_UID_1 2012-06-01 00:00:00 12 CPU_UTILIZATION 100
SERVER_UID_1 2012-01-01 00:00:00 13 CPU_UTILIZATION 30
SERVER_UID_1 2012-06-01 00:00:00 14 CPU_UTILIZATION 10
SERVER_UID_1 2012-06-01 00:00:00 15 CPU_UTILIZATION 20
SERVER_UID_1 2012-06-01 00:00:00 16 CPU_UTILIZATION 50
SERVER_UID_1 2012-06-01 00:00:00 16 CPU_UTILIZATION 50
SERVER_UID_1 2012-06-01 00:00:00 17 CPU_UTILIZATION 60
SERVER_UID_1 2012-06-01 00:00:00 18 CPU_UTILIZATION 70
SERVER_UID_1 2012-06-01 00:00:00 19 CPU_UTILIZATION 80
SERVER_UID_1 2012-06-01 00:00:00 20 CPU_UTILIZATION 40
SERVER_UID_1 2012-06-01 00:00:00 21 CPU_UTILIZATION 20
SERVER_UID_1 2012-06-01 00:00:00 22 CPU_UTILIZATION 10
SERVER_UID_1 2012-06-01 00:00:00 23 CPU_UTILIZATION 20
SERVER_UID_1 2012-06-01 00:00:00 24 CPU_UTILIZATION 10
SERVER_UID_2 2012-06-04 00:00:00 1 MEMORY_UTILIZATION 100
SERVER_UID_2 2012-06-04 00:00:00 2 MEMORY_UTILIZATION 200


ParamBean Class:

package myapp.beans;

import java.sql.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "app_server_health_check_fact")
public class ParamBean {


@Id
@Column(name = "SERVER_UID", nullable = false)
private String server_uid;


@Column(name = "TIME", nullable = false)
private int time;

@Column(name = "DATE", nullable = false)
private Date date;


@Column(name = "APP_PARAM", nullable = false)
private String app_param;


@Column(name = "APP_PARAM_VALUE", nullable = false)
private int app_param_value;


public Date getDate() {
return date;
}


public void setDate(Date date) {
this.date = date;
}



public String getServer_uid() {
return server_uid;
}


public void setServer_uid(String serverUid) {
server_uid = serverUid;
}


public int getTime() {
return time;
}


public void setTime(int time) {
this.time = time;
}


public String getApp_param() {
return app_param;
}


public void setApp_param(String appParam) {
app_param = appParam;
}


public int getApp_param_value() {
return app_param_value;
}


public void setApp_param_value(int appParamValue) {
app_param_value = appParamValue;
}

}


Hibernate Config:

<?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.url">jdbc:mysql://localhost/storefascia</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="myapp.beans.UserBean" />
</session-factory>
</hibernate-configuration>

Can you please suggest what is wrong with this?
The hibernate version used 3.2.6.ga


Top
 Profile  
 
 Post subject: Re: criteriaQuery().list() returning repeated rows
PostPosted: Mon Jun 04, 2012 3:20 pm 
Beginner
Beginner

Joined: Mon Jun 04, 2012 12:31 pm
Posts: 20
Try looking here: https://forum.hibernate.org/viewtopic.php?t=941669


Top
 Profile  
 
 Post subject: Re: criteriaQuery().list() returning repeated rows
PostPosted: Tue Jun 05, 2012 2:38 am 
Newbie

Joined: Mon Jun 04, 2012 8:45 am
Posts: 2
Thanks the problem is solved.
The actual problem is due to missing index in the database table.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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.