-->
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: This set is not clearing the objects.
PostPosted: Wed Jun 16, 2004 6:53 am 
Beginner
Beginner

Joined: Wed Mar 17, 2004 12:44 am
Posts: 25
Hello all,

I have a parent entity with a set of "Files"(super-class). Using discriminator values I have generated another set of domain objects. For the first time when I execute the program I can add/remove the elements from the set. But when I do it for the second time it is not reflecting the database. However the strange thing is that the same set of code is executed in both the cases. I tried printing the size of set for first execution and second execution. First time after the objects are removed from the Set the size of set reduces. But for the second time the size of Set remains the same even if remove() is called over its iterator.

Please suggest me some solution.

Mapping in main XML
<set name="Files" table="METADATA_FILES" inverse="true" lazy="true" cascade="all">
<key column="TUBE_ID"/>
<one-to-many class="com.imc.sts.domain.Files"/>
</set

Mapping in Files XML
<discriminator column="FILETYPE_ID" type="string" />
<subclass name="com.imc.sts.domain.InsertFiles" lazy="false" discriminator-value="1">
</subclass>
<subclass name="com.imc.sts.domain.OtherFiles" lazy="false" discriminator-value="2">
</subclass>
<subclass name="com.imc.sts.domain.GenotypeSeqFiles" lazy="false" discriminator-value="3">
</subclass>
<subclass name="com.imc.sts.domain.VectorFiles" lazy="false" discriminator-value="4">
</subclass>
<subclass name="com.imc.sts.domain.InsertVectorFiles" lazy="false" discriminator-value="5">
</subclass>

Overloaded equals() method in sub-classes :
public boolean equals(Object other) {
if ( !(other instanceof GenotypeSeqFiles) ) return false;
GenotypeSeqFiles castOther = (GenotypeSeqFiles) other;

Object[] selfArray = new Object[] {this.getFilePath()};
Object[] otherArray = new Object[] {castOther.getFilePath()};

return new EqualsBuilder()
.append(selfArray, otherArray)
.isEquals();
}

Code :
// Clear the old files
Set filesSet = tube.getFiles();

if(filesSet == null) {
filesSet = new HashSet();
} else if(filesSet.size() > 0) {

Iterator i = filesSet.iterator();
// Clear the old Files in filesSet
while(i.hasNext()) {
Object obj = i.next();
if(obj instanceof GenotypeSeqFiles || obj instanceof InsertFiles || obj instanceof VectorFiles
|| obj instanceof InsertVectorFiles || obj instanceof OtherFiles){
i.remove();
}
}
}

// Add New files
for(int counter=0; counter < genotypeSeqFilesArray.length; counter++){
GenotypeSeqFiles file = new GenotypeSeqFiles();
file.setParentTube(tube);
file.setFilePath(genotypeSeqFilesArray[counter][0]);
filesSet.add(file);
}

// Set the new files set in the tube object.
tube.setFiles(filesSet);

// Set the domain object in Tube object
tube.setGenotypeSequence(genotypeSequence);


Regards,

Nitin


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.