-->
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.  [ 10 posts ] 
Author Message
 Post subject: Objects are Duplicated in Collection
PostPosted: Thu Oct 30, 2008 9:36 am 
Newbie

Joined: Thu Oct 30, 2008 9:27 am
Posts: 10
Location: indore
HI ,
I have problem sessionFactory.getCurrentSession().createSQLQuery(
query).addEntity(PhysicalItemVerificationViewBean.class).list() ; it returns list but the list contains duplicated rows means same records multiple times . i have override equals and hashcode in bean class but still getting same records .if i use set instead of list some records are missing . Can anybody help me ASAP
Thanks in advance
Naresh Bahety

_________________
Naresh Bahety
Software Engineer
Impetus Infotech Pvt Ltd Indore
Cell:9893073973


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2008 10:58 am 
Beginner
Beginner

Joined: Mon Jan 10, 2005 7:14 am
Posts: 32
When you run your query outside of Hibernate, does it return records twice ? Maybe you miss a DISTINCT clause ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 1:18 am 
Newbie

Joined: Thu Oct 30, 2008 9:27 am
Posts: 10
Location: indore
No, actually when i run query in query browser it returns correct records but i run it through code it returns wrong values .please provide the solution .
thanks for reply.

_________________
Naresh Bahety
Software Engineer
Impetus Infotech Pvt Ltd Indore
Cell:9893073973


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 6:55 am 
Newbie

Joined: Fri Oct 31, 2008 6:27 am
Posts: 4
Quote:
.if i use set instead of list some records are missing

Maybe you need to have a closer look to your implementation of equals()
hashCode().
If some record are missing it just means the corresponding objects were meaningfully equals for your Set.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 6:59 am 
Newbie

Joined: Thu Oct 30, 2008 9:27 am
Posts: 10
Location: indore
no i have generated equals and hashcode through myeclise so there is no chance of mistake .
and this is my bean class

import java.util.Date;

public class PhysicalItemVerificationViewBean {

private Integer itemId;
private String itemName;
private String manufacturer;
private String location;
private String type;
private String batchNumber;
private Date expiryDate;
private Double sysqty;
private Double actualQuantity;

public Integer getItemId() {
return itemId;
}
public void setItemId(Integer itemId) {
this.itemId = itemId;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getBatchNumber() {
return batchNumber;
}
public void setBatchNumber(String batchNumber) {
this.batchNumber = batchNumber;
}
public Date getExpiryDate() {
return expiryDate;
}
public void setExpiryDate(Date expiryDate) {
this.expiryDate = expiryDate;
}
public Double getSysqty() {
return sysqty;
}
public void setSysqty(Double sysqty) {
this.sysqty = sysqty;
}
public Double getActualQuantity() {
return actualQuantity;
}
public void setActualQuantity(Double actualQuantity) {
this.actualQuantity = actualQuantity;
}

public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((actualQuantity == null) ? 0 : actualQuantity.hashCode());
result = prime * result
+ ((batchNumber == null) ? 0 : batchNumber.hashCode());
result = prime * result
+ ((expiryDate == null) ? 0 : expiryDate.hashCode());
result = prime * result + ((itemId == null) ? 0 : itemId.hashCode());
result = prime * result
+ ((itemName == null) ? 0 : itemName.hashCode());
result = prime * result
+ ((location == null) ? 0 : location.hashCode());
result = prime * result
+ ((manufacturer == null) ? 0 : manufacturer.hashCode());
result = prime * result + ((sysqty == null) ? 0 : sysqty.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}

public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final PhysicalItemVerificationViewBean other = (PhysicalItemVerificationViewBean) obj;
if (actualQuantity == null) {
if (other.actualQuantity != null)
return false;
} else if (!actualQuantity.equals(other.actualQuantity))
return false;
if (batchNumber == null) {
if (other.batchNumber != null)
return false;
} else if (!batchNumber.equals(other.batchNumber))
return false;
if (expiryDate == null) {
if (other.expiryDate != null)
return false;
} else if (!expiryDate.equals(other.expiryDate))
return false;
if (itemId == null) {
if (other.itemId != null)
return false;
} else if (!itemId.equals(other.itemId))
return false;
if (itemName == null) {
if (other.itemName != null)
return false;
} else if (!itemName.equals(other.itemName))
return false;
if (location == null) {
if (other.location != null)
return false;
} else if (!location.equals(other.location))
return false;
if (manufacturer == null) {
if (other.manufacturer != null)
return false;
} else if (!manufacturer.equals(other.manufacturer))
return false;
if (sysqty == null) {
if (other.sysqty != null)
return false;
} else if (!sysqty.equals(other.sysqty))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}





}

_________________
Naresh Bahety
Software Engineer
Impetus Infotech Pvt Ltd Indore
Cell:9893073973


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2008 8:07 am 
Newbie

Joined: Thu Oct 30, 2008 9:27 am
Posts: 10
Location: indore
please provide the solution for these problem ASAP.

_________________
Naresh Bahety
Software Engineer
Impetus Infotech Pvt Ltd Indore
Cell:9893073973


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2008 2:25 pm 
Beginner
Beginner

Joined: Wed Sep 24, 2008 5:44 pm
Posts: 34
Can you provide the generated SQL?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2008 1:00 am 
Newbie

Joined: Thu Oct 30, 2008 9:27 am
Posts: 10
Location: indore
the Sql is mentioned below my database is on postgress.

select * from physicalverificationview where LOWER(itemName)='crocin-tab-500mg';


Thanks.

_________________
Naresh Bahety
Software Engineer
Impetus Infotech Pvt Ltd Indore
Cell:9893073973


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 2:25 am 
Newbie

Joined: Wed Nov 19, 2008 1:58 am
Posts: 1
Location: Mumbai
Hi,

Problem is with either the hashCode method or hbm mapping file. In your hashCode method there should be only those fields which are either declare primary key or composite key in hbm file.

I was facing the same problem got resolved after doing the similar changes in hashCode & equals method and ofcourse the hbm file too.

_________________
Thanks & Regards
Dinesh R. Bhogle
Rave Technologies


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 1:47 am 
Newbie

Joined: Thu Oct 30, 2008 9:27 am
Posts: 10
Location: indore
thanks Dinesh for your reply.solution provided by you works .thanks

_________________
Naresh Bahety
Software Engineer
Impetus Infotech Pvt Ltd Indore
Cell:9893073973


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