Customer entity
#Entity
#Table(name="Customer")
public class Customer {
#Id
#GeneratedValue
private Long cusId;
#Column(name="firstname")
private String firstName;
#Column(name="lastname")
private String lastName;
#Column(name="address")
private String add;
#Column(name="tel")
private int tel;
#Column(name="email")
private String email;
#Column(name="userName")
private String username;
#Column(name="password")
private String password;
#OneToMany(fetch = FetchType.EAGER, mappedBy = "customer")
#JsonManagedReference
private List<Complain> complain=new ArrayList<Complain>();
public Customer() {
super();
// TODO Auto-generated constructor stub
}
public Long getCusId() {
return cusId;
}
public void setCusId(Long cusId) {
this.cusId = cusId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAdd() {
return add;
}
public void setAdd(String add) {
this.add = add;
}
public int getTel() {
return tel;
}
public void setTel(int tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<Complain> getComplain() {
return complain;
}
public void setComplain(List<Complain> complain) {
this.complain = complain;
}
}
Complain Entity
#Entity
#Table(name="Complain")
public class Complain {
#Id
#GeneratedValue
private Long id;
#Column(name="repfirst")
private String repfirst;
#Column(name="replast")
private String replast;
#Column(name="warranty")
private String warranty;
#Column(name="dop")
private String purDate;
#Column(name="Nomachine")
private String Nomachine;
#Column(name="Complain")
private String Complain;
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name="cus_id", referencedColumnName = "cusId")
#JsonBackReference
private Customer customer;
public Complain() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getRepfirst() {
return repfirst;
}
public void setRepfirst(String repfirst) {
this.repfirst = repfirst;
}
public String getReplast() {
return replast;
}
public void setReplast(String replast) {
this.replast = replast;
}
public String getWarranty() {
return warranty;
}
public void setWarranty(String warranty) {
this.warranty = warranty;
}
public String getPurDate() {
return purDate;
}
public void setPurDate(String purDate) {
this.purDate = purDate;
}
public String getNomachine() {
return Nomachine;
}
public void setNomachine(String nomachine) {
Nomachine = nomachine;
}
public String getComplain() {
return Complain;
}
public void setComplain(String complain) {
Complain = complain;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
}
I want to pass data to the mysql database through the postman tool. How can I pass value for the foreign key column through the json query?
This is the method I have used in controller
#PostMapping(path="/",consumes="application/json",produces="application/json")
public void addComplain(#RequestBody Complain complain)
{
Integer id = complainService.getAllComplain().size()+1;
complain.setId(new Long(id));
complainService.createOrUpdateComplain(complain); }
After I send the request from the postman, all the data are saved except the foreign key. I think I missed something in mapping two tables.
This is my json query
{"complain":"No power",
"repfirst":"hi",
"replast":"all",
"warranty":"yes",
"purDate":"2020-02-29",
"nomachine":"6",
"tel":"46544654",
"Customer":[
{"cusId":"1"}
]
}
Database table image
Please help, Thanks in advance
{
"repfirst": "",
"replast": "",
"warranty": "",
"purDate" : "",
"Nomachine": "",
"Complain": "",
"cus_id": 1
}
That should work
"Customer":[
{"cusId":"1"}
]
This would work if you had Set<Customer> customers converted to an array in json, for example.
Related
I am having an unusual error, when doing a get in postman, my method returns some values called target and targetClass, I don't know why, since I am implementing an interface just to bring some specific values, if you could help would be very appreciated
This is the model
#Entity
#Table(name = "tudb_users")
public class Tudb_users {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "user_id")
private int userId;
#Column(name = "client_id")
private Integer clientId;
#Column(name = "name")
private String name;
#Column(name = "last_name")
private String lastName;
#Column(name = "rol_id")
private Integer rolId;
#Column(name = "clinic_id")
private Integer clinicId;
#Column(name = "password")
private String password;
#Column(name = "rfc")
private String rfc;
#Column(name = "gender")
private Integer gender;
#Column(name = "date_born")
private String dateBorn;
#Column(name = "email")
private String email;
#Column(name = "phone")
private String phone;
#Column(name = "identification_card")
private String identificationCard;
#Column(name = "photo")
private String photo;
#Column(name = "folder")
private String folder;
#Column(name = "session")
private Integer session;
#Column(name = "promotion_code")
private String promotionCode;
#Column(name = "last_session")
#Temporal(TemporalType.TIMESTAMP)
#JsonFormat(pattern = "yy-MM-dd' 'HH:mm")
private Date lastSession;
#Column(name = "token")
private String token;
#Column(name = "token_email")
private String tokenEmail;
#Column(name = "status")
private Integer status;
#Column(name = "user_register")
private Integer userRegister;
#Column(name = "date_register")
#Temporal(TemporalType.TIMESTAMP)
#JsonFormat(pattern = "yy-MM-dd' 'HH:mm")
private Date dateRegister;
#Column(name = "user_update")
private Integer userUpdate;
#Column(name = "date_update")
#Temporal(TemporalType.TIMESTAMP)
#JsonFormat(pattern = "yy-MM-dd' 'HH:mm")
private Date dateUpdate;
#Column(name = "options")
private Integer options;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public Integer getClientId() {
return clientId;
}
public void setClientId(Integer clientId) {
this.clientId = clientId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Integer getRolId() {
return rolId;
}
public void setRolId(Integer rolId) {
this.rolId = rolId;
}
public Integer getClinicId() {
return clinicId;
}
public void setClinicId(Integer clinicId) {
this.clinicId = clinicId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRfc() {
return rfc;
}
public void setRfc(String rfc) {
this.rfc = rfc;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public String getDateBorn() {
return dateBorn;
}
public void setDateBorn(String dateBorn) {
this.dateBorn = dateBorn;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getIdentificationCard() {
return identificationCard;
}
public void setIdentificationCard(String identificationCard) {
this.identificationCard = identificationCard;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public String getFolder() {
return folder;
}
public void setFolder(String folder) {
this.folder = folder;
}
public Integer getSession() {
return session;
}
public void setSession(Integer session) {
this.session = session;
}
public Date getLastSession() {
return lastSession;
}
public void setLastSession(Date lastSession) {
this.lastSession = lastSession;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getUserRegister() {
return userRegister;
}
public void setUserRegister(Integer userRegister) {
this.userRegister = userRegister;
}
public Date getDateRegister() {
return dateRegister;
}
public void setDateRegister(Date dateRegister) {
this.dateRegister = dateRegister;
}
public Integer getUserUpdate() {
return userUpdate;
}
public void setUserUpdate(Integer userUpdate) {
this.userUpdate = userUpdate;
}
public Date getDateUpdate() {
return dateUpdate;
}
public void setDateUpdate(Date dateUpdate) {
this.dateUpdate = dateUpdate;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getTokenEmail() {
return tokenEmail;
}
public void setTokenEmail(String tokenEmail) {
this.tokenEmail = tokenEmail;
}
public Integer getOptions() {
return options;
}
public void setOptions(Integer options) {
this.options = options;
}
public String getPromotionCode() {
return promotionCode;
}
public void setPromotionCode(String promotionCode) {
this.promotionCode = promotionCode;
}
}
Now this is repository
#Repository
public interface TudbUsersRepository extends JpaRepository<Tudb_users, Long>{
#Query(value = "SELECT tudb_users.user_id, tudb_users.client_id, tu_clients.name as nameCliente, tudb_users.clinic_id, tudb_users.rol_id, tudb_roles.description as rolName, tudb_users.name, tudb_users.last_name,\r\n"
+ "tudb_users.email, tudb_users.photo, tudb_users.rfc, tudb_users.gender, tudb_users.date_born, tudb_users.folder, tudb_users.token\r\n"
+ "FROM dentabash_dev.tudb_users inner join tu_clients on tu_clients.client_id = tudb_users.client_id\r\n"
+ "inner join tudb_roles on tudb_roles.rol_id = tudb_users.rol_id where tudb_users.client_id = ?1", nativeQuery = true)
List<DentaUser> getUsersByClientId(Integer id);
}
This is the interface
public interface DentaUser {
Integer getUser_id();
Integer getClient_id();
Integer getClinic_id();
Integer getRol_id();
String getNameCliente();
String getRolName();
String getName();
String getLast_name();
String getEmail();
String getPhoto();
String getRfc();
Integer getGender();
#Temporal(TemporalType.TIMESTAMP)
#JsonFormat(pattern = "yy-MM-dd' 'HH:mm")
Date getDate_born();
String getFolder();
String getToken();
}
This is the service
#Service
public class TudbUsersServices {
#Autowired
private TudbUsersRepository repo;
public ResponseEntity<?> getUserByClientID(Integer id){
JSONObject response = new JSONObject();
try {
response.put("code", 200);
response.put("success", true);
response.put("data", repo.getUsersByClientId(id));
return new ResponseEntity<>(response.toString(), HttpStatus.OK);
}catch(Exception e) {
response.put("code", 400);
response.put("success", false);
response.put("message", "Bad request" + e.getMessage());
return new ResponseEntity<>(response.toString(), HttpStatus.OK);
}
}
}
And this is controller:
#RestController
#RequestMapping("/dbusers")
#Tag(name = "DentaBash Users", description = "DentaBash Users - Controller")
#CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST})
public class TudbUsersController {
#Autowired
private TudbUsersServices service;
#RequestMapping(value = "/usersByClient", method = RequestMethod.GET)
public ResponseEntity<?> getUserByClientID(#RequestParam Integer clientId){
return service.getUserByClientID(clientId);
}
}
Now I get this in postman:
{
"code": 200,
"data": [
{
"gender": 0,
"photo": "images/user.png",
"last_name": "Ortiz",
"client_id": 2,
"rfc": "TESTRFC",
"target": {
"gender": 0,
"last_name": "Ortiz",
"photo": "images/user.png",
"client_id": 2,
"rfc": "TESTRFC",
"token": "5mi7oit016l768aaj1mecgmgu6",
"folder": "images/test/folder",
"user_id": 4,
"date_born": "2022-02-01",
"name": "Juan",
"nameCliente": "Jose Luis Miranda Pavon",
"rol_id": 4,
"rolName": "Cirujano Dentista - Gerente",
"clinic_id": 1,
"email": "juan#gmail.com"
},
"token": "5mi7oit016l768aaj1mecgmgu6",
"folder": "images/test/folder",
"user_id": 4,
"targetClass": "class org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap",
"name": "Juan",
"nameCliente": "Jose Luis Miranda Pavon",
"rol_id": 4,
"rolName": "Cirujano Dentista - Gerente",
"clinic_id": 1,
"email": "juan#gmail.com"
}
],
"success": true
}
I have difficult to figure out to create an object in a class for jUnit test.
In my test I have : User user = new User(); , and I receive a
java.lang.reflect.InvocationTargetException cathed into
public abstract class ReflectiveCallable {
public Object run() throws Throwable {
try {
return runReflectiveCall();
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
This is my User class:
#Entity
public class User implements Serializable{
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
private Double internalKey = (new Random()).nextDouble();
protected User() {
super();
}
public User(String firstName, String lastName) {
super();
this.firstName = firstName;
this.lastName = lastName;
}
public Long getId() {
return id;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getInternalKey() {
return internalKey;
}
}
What is wrong? thanks
it's me again. so i have this javafx tableview which i have loaded dynamically with rows and columns from my database. it works out well but there's something i realized. two particular columns in the tableview switch their values. it happened once and when i cancelled the process and ran the program again, it didn't happen, then out of the blues, it happened again. i attached an image so you'd understand better. THANKS GUYS!!
below is the code that populates the tableview with Columns and rows from the database. i don't get any error when i run this.
public void buildData () {
String str = "SELECT * FROM EMPLOYEE_TABLE";
data = FXCollections.observableArrayList();
try {
ResultSet rs = DBaseUtils.dbaseExecuteQuery(str);
for(int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
String columnName = rs.getMetaData().getColumnName(i + 1);
TableColumn<Employee, String> column = new TableColumn<>(columnName);
column.setCellValueFactory(new PropertyValueFactory<>(columnName));
column.setCellFactory(TextFieldTableCell.<Employee>forTableColumn());
column.setOnEditCommit(new EventHandler<>() {
#Override
public void handle(TableColumn.CellEditEvent<Employee, String> event) {
TableColumn<Employee, String> col = event.getTableColumn();
int row = event.getTablePosition().getRow();
ObservableValue<String> observe = col.getCellObservableValue(row);
if (observe instanceof WritableValue) {
((WritableValue<String>) observe).setValue(event.getNewValue());
}
}
});
empTable.getColumns().addAll(column);
}
while(rs.next()) {
Employee emp = new Employee();
emp.setEmployeeId(rs.getString(1));
emp.setFirstname(rs.getString(2));
emp.setLastname(rs.getString(3));
emp.setSex(rs.getString(4));
emp.setEmail(rs.getString(5));
emp.setPhoneNumber(rs.getString(6));
emp.setAddress(rs.getString(7));
emp.setHireDate(rs.getString(8));
emp.setState(rs.getString(9));
emp.setSalary(rs.getString(10));
emp.setDepartment(rs.getString(11));
emp.setSsn(rs.getString(12));
data.add(emp);
}
empTable.setItems(data);
empTable.setEditable(true);
} catch(Exception e) {
e.printStackTrace();
System.out.println("Error building data! ");
}
}
i also attached the model class, well... just in case.
notice the naming conventions for the Property methods, i had to use that because those were the exact names on my database. and since it PropertyValueFactory uses Reflection.
public class Employee {
private SimpleStringProperty employeeId;
private SimpleStringProperty firstname;
private SimpleStringProperty lastname;
private SimpleStringProperty sex;
private SimpleStringProperty email;
private SimpleStringProperty phoneNumber;
private SimpleStringProperty hireDate;
private SimpleStringProperty address;
private SimpleStringProperty state;
private StringProperty salary;
private SimpleStringProperty department;
private SimpleStringProperty ssn;
private long time;
public Employee() {
this.employeeId = new SimpleStringProperty();
this.firstname = new SimpleStringProperty();
this.lastname = new SimpleStringProperty();
this.sex = new SimpleStringProperty();
this.email = new SimpleStringProperty();
this.phoneNumber = new SimpleStringProperty();
this.hireDate = new SimpleStringProperty();
this.address = new SimpleStringProperty();
this.state = new SimpleStringProperty();
this.salary = new SimpleStringProperty();
this.department = new SimpleStringProperty();
this.ssn = new SimpleStringProperty();
}
public String getEmployeeId() {
return employeeId.get();
}
public void setEmployeeId(String id) {
this.employeeId.set(id);
}
public StringProperty EMPLOYEE_IDProperty() {
return employeeId;
}
public String getFirstName() {
return firstname.get();
}
public void setFirstname(String firstname) {
this.firstname.set(firstname);
}
public StringProperty FIRST_NAMEProperty() {
return firstname;
}
public String getLastName() { return lastname.get(); }
public void setLastname(String lastname) {
this.lastname.set(lastname);
}
public StringProperty LAST_NAMEProperty() {
return lastname;
}
public String getSex() {
return sex.get();
}
public void setSex(String sex) {
this.sex.set(sex);
}
public StringProperty SEXProperty() {
return sex;
}
public String getEmail() {
return email.get();
}
public void setEmail(String email) {
this.email.set(email);
}
public StringProperty EMAILProperty() {
return email;
}
public String getPhoneNumber() {
return phoneNumber.get();
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber.set(phoneNumber);
}
public StringProperty PHONE_NUMBERProperty() {
return phoneNumber;
}
public String getHireDate() {
return hireDate.get();
}
public void setHireDate(String date) {
this.hireDate.set(date);
}
public SimpleStringProperty HIRE_DATEProperty() {
return hireDate;
}
public String getAddress() {
return address.get();
}
public void setAddress(String address) {
this.address.set(address);
}
public StringProperty ADDRESSProperty() {
return address;
}
public String getState() {
return state.get();
}
Here's the image. notice the different values in the HIRE_DATE COLUMN AND ADDRESS COLUMN
I am working on deserializing the below JSON:
{"self":"http://members.cs.com/rest/api/user?username=abc#cs.com",
"key":"abc#cs.com",
"name":"abc#cs.com",
"emailAddress":"abc#cs.com",
"displayName":"ABC",
"active":true,
"members":{"size":1,"items":[{"name":"member-users","self":"http://members.cs.com/rest/api/user?username=abc#cs.com"}]},
"expand":"members"}
I have created the following classes:
#JsonIgnoreProperties(ignoreUnknown = true)
public class UserList {
private String name;
private String emailAddress;
private String displayName;
private boolean active;
List<MemberName> members = new ArrayList<>();
#JsonCreator
public UserList(#JsonProperty("name") String name, #JsonProperty("emailAddress") String emailAddress, #JsonProperty("displayName") String displayName, #JsonProperty("active") boolean active, #JsonProperty("members") List<MemberName> members) {
this.name = name;
this.emailAddress = emailAddress;
this.displayName = displayName;
this.active = active;
this.members.addAll(groups);
}
//getters
}
#JsonIgnoreProperties(ignoreUnknown = true)
public class MemberName {
private String name;
#JsonCreator
public MemberName(#JsonProperty("name") String name) {
this.name = name;
}
public String getName() {
return name;
}
}
When I don't give the members as a property the deserialization works fine and I can see the values for the name, displayName, active, emailAddress. The problem happens with the MemberName.
Could someone help with this?
This worked for me:
Class Items as below:
public class Items {
private String name;
private String self;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSelf() {
return self;
}
public void setSelf(String self) {
this.self = self;
}
}
Members class as below:
public class Members {
private int size;
private List<Items> items;
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public List<Items> getItems() {
return items;
}
public void setItems(List<Items> items) {
this.items = items;
}
}
Data class as below:
public class Data {
private String self;
private String key;
private String name;
private String emailAddress;
private String displayName;
private boolean active;
private Members members;
private String expand;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSelf() {
return self;
}
public void setSelf(String self) {
this.self = self;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public Members getMembers() {
return members;
}
public void setMembers(Members members) {
this.members = members;
}
public String getExpand() {
return expand;
}
public void setExpand(String expand) {
this.expand = expand;
}
}
The deserialization as below:
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
String jsonString = "{\"self\": \"http://members.cs.com/rest/api/user?username=abc#cs.com\",\"key\": \"abc#cs.com\",\"name\": \"abc#cs.com\","
+ "\"emailAddress\": \"abc#cs.com\",\"displayName\": \"ABC\",\"active\": true,\"members\": {\"size\": 1,\"items\": [{"
+ "\"name\": \"member-users\",\"self\": \"http://members.cs.com/rest/api/user?username=abc#cs.com\" }]},\"expand\": \"members\"}";
ObjectMapper mapper = new ObjectMapper();
Data obj = mapper.readValue(jsonString,Data.class);
System.out.println(obj.getSelf());
System.out.println(obj.getKey());
System.out.println(obj.getName());
System.out.println(obj.getEmailAddress());
System.out.println(obj.getDisplayName());
System.out.println(obj.isActive());
System.out.println(obj.getMembers().getSize());
System.out.println(obj.getMembers().getItems().get(0).getName());
System.out.println(obj.getMembers().getItems().get(0).getSelf());
System.out.println(obj.getExpand());
}
Ok i have class User
#Entity
#Table(name = "users")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue
private Long id_user;
#Column(nullable = false)
private String email;
#Column(nullable = true)
private String password;
private String firstname;
private String lastname;
private Boolean enabled;
private String phone;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "id_company")
private Company company;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "id_rank")
#JsonBackReference
private Authority authorities;
#OneToMany(mappedBy = "create_by")
private List<Cms> create_by;
#OneToMany(mappedBy = "modified_by")
private List<Cms> modified_by;
#OneToMany(mappedBy = "id_issuer")
private List<Ticket> id_issuer;
#OneToMany(mappedBy = "id_responsible")
private List<Ticket> id_responsible;
#OneToMany(mappedBy = "id_author")
private List<IssueMsg> id_author;
public User() {
}
public User(String email, String password, String firstname, String lastname, String phone, Company company, Authority authority) {
this.email = email;
this.password = password;
this.firstname = firstname;
this.lastname = lastname;
this.enabled = true;
this.phone = phone;
this.authorities = authority;
}
#Override
public String toString() {
return "User [id_user=" + id_user + ", email=" + email + ", password="
+ password + ", firstname=" + firstname + ", lastname="
+ lastname + ", enabled=" + enabled + ", phone=" + phone
+ "]";
}
public Long getId_user() {
return id_user;
}
public void setId_user(Long id_user) {
this.id_user = id_user;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
#JsonIgnore
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public Company getCompany() {
return company;
}
public void setCompany(Company company) {
this.company = company;
}
/**
* #return the authorities
*/
public Authority getAuthorities() {
return authorities;
}
/**
* #param authorities the authorities to set
*/
public void setAuthorities(Authority authority) {
this.authorities = authority;
}
#JsonIgnore
public List<Cms> getCreate_by() {
return create_by;
}
public void setCreate_by(List<Cms> create_by) {
this.create_by = create_by;
}
#JsonIgnore
public List<Cms> getModified_by() {
return modified_by;
}
public void setModified_by(List<Cms> modified_by) {
this.modified_by = modified_by;
}
#JsonIgnore
public List<Ticket> getId_issuer() {
return id_issuer;
}
public void setId_issuer(List<Ticket> id_issuer) {
this.id_issuer = id_issuer;
}
#JsonIgnore
public List<Ticket> getId_responsible() {
return id_responsible;
}
public void setId_responsible(List<Ticket> id_responsible) {
this.id_responsible = id_responsible;
}
#JsonIgnore
public List<IssueMsg> getId_author() {
return id_author;
}
public void setId_author(List<IssueMsg> id_author) {
this.id_author = id_author;
}
}
And class Company
#Entity
#Table(name = "companies")
public class Company implements Serializable {
private static final long serialVersionUID = 6255059577246367312L;
#Id
#GeneratedValue
private Long id_company;
private String name;
private String adress;
private String email;
private String phone;
#OneToMany(mappedBy = "company")
#JsonManagedReference
private List<User> user;
#Override
public String toString() {
return "Company [id_company=" + id_company + ", name=" + name
+ ", adress=" + adress + ", email=" + email + ", phone="
+ phone + "]";
}
public Company() {
}
public Company(Long id_company, String name, String adress, String email,
String phone) {
this.id_company = id_company;
this.name = name;
this.adress = adress;
this.email = email;
this.phone = phone;
}
public Long getId_company() {
return id_company;
}
public void setId_company(Long id_company) {
this.id_company = id_company;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public List<User> getUser() {
return user;
}
public void setUser(List<User> user) {
this.user = user;
}
}
I getting all result from database, and returning this as response body.
My JSON response get user.company.user list and i don't need what. I was try add on getter company user #JsonIgnore but i getting error
com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.ArrayList[1]->projektzespolowy.model.User["company"]->projektzespolowy.model.Company_$$_jvstcb8_2["handler"])
I read many post about fix thix but no one help. This is possible to ignore this user list in company?
I think you are getting this exception because User#company is lazy fetched so jackson tries to serialize a hibernate proxy. Try with fetch = FetchType.EAGER on the mapping, or call user.getCompany() in the controller prior to returning the results.