Why do I get 2 sets of children when i use setAsyncValue?

125
January 11, 2019, at 11:20 AM

I'm not sure why 2 children are created/updated when using setValueAsync. Maybe someone can help me understand what I'm doing wrong.

Initially I setup manually under the Employee node some children (Name and Password). Now I'm trying to create a process to be able to update them from an app in java. For some unknown reason 2 sets of children are created/updated(appPassword,name,password,technicianName). even If I delete any of the sets they are added automatically when I do a setValueAsync.

here is my class:

package com.mycompany.spring.model;
public class TechShort {
    public boolean active;
    public String name;
    public String password;
public TechShort(boolean active, String name, String password) {
    this.active;
    this.name = name;
    this.password = password;
}
public boolean getActive() {return this.active;}
public void setActive(boolean active) {this.active = active;} 
public String getTechnicianName() {return this.name;}
public void setTechnicianName(String name) {this.name = name;}     
public String getAppPassword() {return this.password;}
public void setAppPassword(String password) {this.password = password;}     
}

and this is how I load firebase database:

Map<String, TechShort> techs;
techs = new HashMap<>();
techs.put((String.valueOf(i+1)),
       new  TechShort(Boolean.valueOf(model.getValueAt(i,6).toString()),
                                name1,password1));
 FirebaseDatabase firedb = FirebaseDatabase.getInstance();
                    DatabaseReference db = firedb.getReference().child("Employees");
                    db.setValueAsync(techs);

so everything works and the children are created but they are duplicated and I would expect to have just 3 children under the node( example active: true password: 1123223 name: george

instead I have: active: true appPassword: 1123223 name: george password: 1123223 technicianName: george

If i change one of the values(ex. 1123223 to something else both appPassword and password are updated. Hopefully someone can help/guide me to understand how to resolve this.

Answer 1

as soon as I modified the getters/setters from:

public boolean getActive() {return this.active;}
public void setActive(boolean active) {this.active = active;} 
public String getTechnicianName() {return this.name;}
public void setTechnicianName(String name) {this.name = name;}     
public String getAppPassword() {return this.password;}
public void setAppPassword(String password) {this.password = password;}

to

public boolean getActive() {return this.active;}
public void setActive(boolean active) {this.active = active;} 
public String getName() {return this.name;}
public void setName(String name) {this.name = name;}     
public String getPassword() {return this.password;}
public void setPassword(String password) {this.password = password;}  

the duplication disappeared. it seems that the getters/setters and the variables should match otherwise there will be duplicates.

READ ALSO
Can multiple (or the same) methods be running simultaneously on one instance? [on hold]

Can multiple (or the same) methods be running simultaneously on one instance? [on hold]

I'm attempting to make a video game and am worried about working with my world object in multiple threads

68
Equivalent of const(C++) in Java

Equivalent of const(C++) in Java

I was wondering if there was an equivalent to c++'s const in JavaI understand the final keyword, but unfortunately I cannot use that to declare a functions return value final

43
How to resolve java.lang.ClassNotFoundException: DocumentException

How to resolve java.lang.ClassNotFoundException: DocumentException

I am using Spring Boot with spring security application, i am getting below exception while starting the application

62