-->
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.  [ 1 post ] 
Author Message
 Post subject: [session.get] problems getting an object with composite id
PostPosted: Fri May 27, 2011 6:49 am 
Beginner
Beginner

Joined: Mon Apr 18, 2011 10:01 am
Posts: 20
Dear forum users, --please do not think TL;DR--
I wish to better understand how the session.get(...) method works, in case of an entity with composite id.

I have a class PcTaskAssignee.java , defined as follows :

Code:
package previtc.model.task;

import java.io.Serializable;
import org.apache.commons.lang.builder.HashCodeBuilder;
import previtc.model.AssigneeCompare;
import previtc.model.EntityObject;

public class PcTaskAssignee extends EntityObject implements Serializable {

    private String  taskId   = null;
    private Double  version  = new Double(0.0);
    private String  assignee = null;
    private String  phone    = null;
    private String  email    = null;
    private String  guid     = null;
    private String  isGroup  = null;

    public PcTaskAssignee() {
    }
    public int hashCode(){
        return new HashCodeBuilder()
            .append(taskId)
            .append(version)
            .append(assignee)
            .toHashCode();
    }
    public boolean equals(AssigneeCompare compare){
        if(this.taskId.equals(compare.getId())
          //&&(this.version.equals(compare.getVersion()) )
          &&(this.assignee.equals(compare.getAssignee()) ) )
            return true;
        else
            return false;
    }
    public String getName(){
        return assignee;
    }
    public void setAssignee(String assignee) {
        this.assignee = assignee;
    }
    public String getAssignee() {
        return assignee;
    }
    public void setGuid(String guid) {
        this.guid = guid;
    }


    public String getGuid() {
        return guid;
    }
    public void setIsGroup(String isGroup) {
        this.isGroup = isGroup;
    }
    public String getIsGroup() {
        return isGroup;
    }
    public boolean sonoPiuAssegnatariDelGruppo(String groupId) {
        if ( (isGroup.equalsIgnoreCase("F"))    ||
             (isGroup==null)                    ||
             (this.guid.equals(groupId)) ){
            return false;
        } else {
            return true;
        }
    }
    public boolean sonoPiuAssegnatari() {
        if (isGroup==null || isGroup.equalsIgnoreCase("F")){
            return false;
        } else {
            return true;
        }
    }
    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }
    public String getTaskId() {
        return taskId;
    }
    public void setVersion(Double version) {
        this.version = version;
    }
    public Double getVersion() {
        return version;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getPhone() {
        return phone;}
    public void setEmail(String email) {
        this.email = email;}
    public String getEmail() {
        return email;}
}


and mapped as follows :

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="previtc.model.task">
    <class name="PcTaskAssignee" table="PC_TASKASSIGNEE" dynamic-update="true" dynamic-insert="true">
        <composite-id>
            <key-property name="taskId"   type="string" column="TASKID"  />           
            <key-property name="version"  type="double" column="VERSION" />
            <key-property name="assignee" type="string" column="ASSIGNEE"/>
        </composite-id>
        <property name="phone"      type="string"       column="PHONE"  />
        <property name="email"      type="string"       column="EMAIL"  />
        <property name="guid"       type="string"       column="GUID"   />
        <property name="isGroup"    type="string"       column="ISGROUP"/>
    </class>
</hibernate-mapping>


I wish to retrieve a single instance of PcTaskAssignee having taskId = xx version = yy and assignee = zz , so I wrote the following

PcTaskAssignee assignatario = (PcTaskAssignee)getSession().get(PcTaskAssignee.class,compare);

where compare is a comparing object, inizialized with the values xx,yy,zz which I want to correspond in PcTaskAssignee. compare is defined as follows
Code:
package previtc.model;
import java.io.Serializable;
public class AssigneeCompare implements Serializable{
    public AssigneeCompare() {
    }
   
    public AssigneeCompare(String taskId,Double version) {
        this.id = taskId;
        this.version = new Double(version.doubleValue());
    }
   
    String id;
    String assignee;
    Double version;[... getters/setters here ...]


but I'm getting exception

exception setting property value with CGLIB (set
hibernate.cglib.use_reflection_optimizer=false for more info) setter of previtc.model.task.PcTaskAssignee. ?


I just want to understand how to use the method equals() and hashCode() to implement a filtering criteria which I explained
above. Could somebody explain me this ?

Thanks a lot, Renato.

P.S. I am using Oracle Database , and my PcTaskAssignee corresponding table is defined as follows :

CREATE TABLE PC_TASKASSIGNEE
(
TASKID NVARCHAR2(32),
VERSION NUMBER,
ASSIGNEE NVARCHAR2(200),
GUID NVARCHAR2(32),
ISGROUP NVARCHAR2(2),
PHONE NVARCHAR2(100),
EMAIL NVARCHAR2(100)
)


I read on the internet that this problem is usually caused by attempting to set a null value to a row / field / attribute which is defined as a primitive ( for example trying to set boolean b = null )


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.