-->
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.  [ 2 posts ] 
Author Message
 Post subject: Using Composite id only first data is show from list
PostPosted: Thu Apr 29, 2004 2:43 am 
Newbie

Joined: Wed Dec 17, 2003 11:55 am
Posts: 10
Following are the xml and .java files for composite id
I have tested the sql query generated by hibernate.
It shows correct result. But when i am retrieved this data by session.find
It is storing only the first record in the list even though there are many records. I have also given the snapshot of the code return for retrieval.
Please guide.
FL3.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD-2.0//EN"
"hibernate-mapping-2.0.dtd">


<hibernate-mapping>
<class name="com.mbl.gcs.common.security.hibernate.FL3" table="FL3" dynamic-update="true">
<composite-id name="operationsPK" class="com.mbl.gcs.common.security.hibernate.FL3PK">
<key-property name="role" column="ROLE"/>
<key-property name="operationCode" column="OPERATION_CODE"/>
</composite-id>
<property name="userId" column="USER_ID"/>
<property name="lastUpTad" column="LAST_UP_TAD"/>
</class>

</hibernate-mapping>

FL3.java
public class FL3 {

/**
* Constructor for FL3.
*/
public FL3() {
super();
}

private FL3PK operationsPK = new FL3PK();
private String userId = null; // USER_ID CHAR
private Date lastUpTad = null; // LAST_UP_TAD DATE

/**
* Returns the operationsPK.
* @return FL3PK
*/
public FL3PK getOperationsPK() {
return operationsPK;
}

/**
* Sets the operationsPK.
* @param operationsPK The operationsPK to set
*/
public void setOperationsPK(FL3PK operationsPK) {
this.operationsPK = operationsPK;
}

/**
* Returns the lastUpTad.
* @return Date
*/
public Date getLastUpTad() {
return lastUpTad;
}

/**
* Returns the userId.
* @return String
*/
public String getUserId() {
return userId;
}

/**
* Sets the lastUpTad.
* @param lastUpTad The lastUpTad to set
*/
public void setLastUpTad(Date lastUpTad) {
this.lastUpTad = lastUpTad;
}

/**
* Sets the userId.
* @param userId The userId to set
*/
public void setUserId(String userId) {
this.userId = userId;
}

public boolean equals(Object a){
return true;
}

public int hashCode(){
return 0;
}


}


FL3PK
public class FL3PK implements java.io.Serializable {

/**
* Constructor for FL3.
*/
public FL3PK() {
super();
}

private String role = null; // ROLE CHAR
private String operationCode = null; // OPERATION_CODE CHAR

/**
* Returns the role.
* @return String
*/
public String getRole() {
return role;
}

/**
* Sets the role.
* @param role The role to set
*/
public void setRole(String role) {
this.role = role;
}
/**
* Returns the operationCode.
* @return String
*/
public String getOperationCode() {
return operationCode;
}

/**
* Sets the operationCode.
* @param operationCode The operationCode to set
*/
public void setOperationCode(String operationCode) {
this.operationCode = operationCode;
}
public boolean equals(Object a){
return true;
}

public int hashCode(){
return 0;
}


}




public ArrayList getOperationsRolesMapping(String userRole) throws Exception
{
ArrayList roles = new ArrayList();
ArrayList role = new ArrayList();

Session session = null;
Connection connection = null;
String sqlQuery = "from objectOfOps in class com.mbl.gcs.common.security.hibernate.FL3 where objectOfOps.operationsPK.role = 'testadmin' order by objectOfOps.operationsPK.operationCode desc";

session = DACommonHibernateSession.openSession();
List list = session.find(sqlQuery);
role.add(objectOfOperations.getOperationsPK().getRole());
Logger.print("objectOfOperations.getRole() in DA : - > " + objectOfOperations.getOperationsPK().getRole());
role.add(objectOfOperations.getOperationsPK().getOperationCode());
Logger.print("objectOfOperations.getOperation() in DA : - > " + objectOfOperations.getOperationsPK().getOperationCode());


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 6:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
only first data is show from list


i've only read this and i had it in the past when composite id wasn't well defined, what about your equals & hashcode?


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