Hello, from time to time i encounter such exception:
"More than one row with the given identifier was found: DeploymentPK@40f5ce59, for class: OwsmServicesDeployment"
I'm using hibernate 3.3.1.GA as JPA realization and ehcache as 2-nd and 3-rd(query) level caches.
Most interesting that exception occurs not alwaus but rarely and without obvios connection to external conditions, i mean i can query same query 10 times and can get or not this exception (Sooth to say, i cant reproduce it on test environment).
I'm using rather simple configuration of my entities without any joins or relations (but data is taken from db view - not from table):
Entity Deployment:
Code:
@Entity
@Table(name="DEPLOYMENT")
public class Deployment implements DeploymentAbstract, Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private DeploymentPK id;
@Column(name="CODE", insertable=false, updatable=false)
private String Code;
@Column(name="SID", insertable=false, updatable=false)
private String Sid;
@Column(name="NATIVE_REG_ID", insertable=false, updatable=false)
private String nativeRegId;
@Column(name="REGION_ID", insertable=false, updatable=false)
private String RegionId;
getters/setters
}
And id:
Code:
@Embeddable
public class DeploymentPK implements DeploymentPKAbstract, Serializable {
private static final long serialVersionUID = 5675951380093663967L;
@Column(name="CODE", unique = true, insertable=false, updatable=false)
private String Code;
@Column(name="SID", unique = true, insertable=false, updatable=false)
private String Sid;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((Code == null) ? 0 : Code.hashCode());
result = prime * result + ((Sid == null) ? 0 : Sid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DeploymentPK other = (DeploymentPK) obj;
if (Code == null) {
if (other.Code != null)
return false;
} else if (!Code.equals(other.Code))
return false;
if (Sid == null) {
if (other.Sid != null)
return false;
} else if (!Sid.equals(other.Sid))
return false;
return true;
}
And query that causes error:
Code:
<named-query name="DeploymentBySIDandRegion">
<query>select a from Deployment a where a.RegionId = :RegionId and a.Sid = :sid</query>
<hint name="org.hibernate.cacheable" value="true"/>
</named-query>
I don't expect that anybody will help me with exactly this situation, but i want to ask some questions:
1) As i've seen in hibernate code, this exception occurs at method
Code:
org.hibernate.loader.entity.AbstractEntityLoader.load(
SessionImplementor session,
Object id,
Object optionalObject,
Serializable optionalId,
LockOptions lockOptions)
I wasn't able to trace what's happening furter in hibernate code, so i want to ask if this method tries to hit the cache?
2)Is there some probability that 2 or more same records could be placed in cache at some conditions? (i'm using memory and disc cache) Can memory and disc cache conflict in some way?
3) Can it be that 2 different queries that query same entity may conflict?
I've been told that exception started to occur after disc cache was set. But i've searced, googled, and nowhere was able to find any references regarding such conflicts.
Can anybody share some suggestions about my situation or answer any of my questions please? (sorry for my english)