Multiple HashMap Problem.

Hi All,I have 2 HashMaps in my Class. I execute query fetch the data from data base and put it on HashMap 1. Then i execute another query and fetch the data and put it on HashMap 2. But the HashMap 2 also update HashMap 1. I dont know why it is happening.Uzair
[281 byte] By [uzairbaig@msn.coma] at [2007-11-27 8:52:40]
# 1
Post some (formatted) code. But I reckon it's because you don't realise that an object can be referenced in more than one HashMap at once
georgemca at 2007-7-12 21:08:34 > top of Java-index,Core,Core APIs...
# 2

Hi,

one reason is because you are referencing the same objects from Map 1 and Map 2?

Map m1 = new HashMap();

m1.put( 搆ey? new Point() );

Point p = (Point) m1.get(搆ey?;

p.setX( 100 );

Map m2 = new HashMap();

m2.put( 搆ey? p );// Same Point in another map

println( m1.get(搆ey? ); // [100,0]

There is only one Point which is referenced from both maps.

Best wishes,

Christian Ullenboom | http://www.tutego.com/

Christian.Ullenbooma at 2007-7-12 21:08:34 > top of Java-index,Core,Core APIs...
# 3
> Post some (formatted) code. But I reckon it's because> you don't realise that an object can be referenced> in more than one HashMap at onceOr worse, hashMap1 and hashMap2 both refer to the same HashMap object?
OleVVa at 2007-7-12 21:08:34 > top of Java-index,Core,Core APIs...
# 4

> > Post some (formatted) code. But I reckon it's

> because

> > you don't realise that an object can be

> referenced

> > in more than one HashMap at once

>

> Or worse, hashMap1 and hashMap2 both refer to the

> same HashMap object?

More likely actually, yeh. Irrelevant now though, the bloody aliens have taken another developer, never to be seen again

georgemca at 2007-7-12 21:08:34 > top of Java-index,Core,Core APIs...
# 5

> More likely actually, yeh. Irrelevant now though, the

> bloody aliens have taken another developer, never

> to be seen again

Thank you for your comment.

Uzair seems to be posting approximately once a year, so maybe the aliens will bring him or her back next year? Impossible to say whether he or she will still have the same problem by then.

;-) ;-)

OleVVa at 2007-7-12 21:08:34 > top of Java-index,Core,Core APIs...