jabbers
jabbers
Explore posts from servers
JCHJava Community | Help. Code. Learn.
Created by jabbers on 11/30/2024 in #java-help
SpringBoot missing certain fields on auto generated repository
Hello, I have a maven springboot project using an H2 database. I have a module class with three fields; name, code and mnc You can see the first few lines of this class below
@Entity
public class Module {

@Id
@Column
private String code;

@Column
private String name;

@Column
private Boolean mnc = false;

/**
* Creates a new Module object.
*/
public Module(String code, String name, boolean mnc) {
super();
this.code = code;
this.name = name;
this.mnc = mnc;
}

public Module() {}

// Getters
public String getCode() {
return code;
}
@Entity
public class Module {

@Id
@Column
private String code;

@Column
private String name;

@Column
private Boolean mnc = false;

/**
* Creates a new Module object.
*/
public Module(String code, String name, boolean mnc) {
super();
this.code = code;
this.name = name;
this.mnc = mnc;
}

public Module() {}

// Getters
public String getCode() {
return code;
}
As you can see code has a corresponding getter (getCode() method), and with my ModuleRepository interface:
public interface ModuleRepository extends CrudRepository<Module, String> {
}
public interface ModuleRepository extends CrudRepository<Module, String> {
}
You would expect the "code" variable to be visible when making a REST request. However, no matter what I seem to do, I can only seem to get the following response with two of the three variables.
{
"_embedded" : {
"modules" : [ {
"name" : "aa",
"mnc" : false,
"_links" : {
"self" : {
"href" : "http://localhost:2800/modules/CS2800"
},
"module" : {
"href" : "http://localhost:2800/modules/CS2800"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:2800/modules"
},
"profile" : {
"href" : "http://localhost:2800/profile/modules"
}
}
}
{
"_embedded" : {
"modules" : [ {
"name" : "aa",
"mnc" : false,
"_links" : {
"self" : {
"href" : "http://localhost:2800/modules/CS2800"
},
"module" : {
"href" : "http://localhost:2800/modules/CS2800"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:2800/modules"
},
"profile" : {
"href" : "http://localhost:2800/profile/modules"
}
}
}
As well as this, the code variable in the database is definitely updated, it just doesn't display in the json response. Thanks in advance.
29 replies