My issue: i use findall method via JPArepository interface to interact with a mysql database. Findall returns a only 4 attributes of my class among 10. All entries are returned but are not complete. Furthermore when i make an axios post from my frontend react application only the same 4 fields are recorded inside database, the remaining 6 attributes are null inside the table. here are my settings:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase?useSSL=false&serverTimezone=UTC
spring.datasource.username=xxxxxx
spring.datasource.password=xxxx
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql: true
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.format_sql=true
If you want to see any part of my code i can send it.
beikov
April 27, 2023, 7:22am
2
Yeah, share all the code and then we can talk further.
Sure! here is my user class:
import jakarta.persistence.*;
import java.sql.Date;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
@Entity
@Table(name = "usertable")
public class User {
public User() {
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long user_id;
@Column
private String lastName;
public enum Role {
Student, Teacher, Admin
}
public enum Level {
Primaire, Collège, Lycée, Supérieur
}
@Column
private String firstName;
@Column
private Level level;
@Column
private String city;
@Column
private String picture;
@Column
private String pseudo;
@Column
private String email;
@Column
private String password;
@Column
private String phone;
@Column
private Date dateOfBirth;
@Column
private Role role;
public User(String lastName, String firstName, Level level, String city, String picture, String pseudo, String email, String password, String phone, Date dateOfBirth, Role role) {
this.lastName = lastName;
this.firstName = firstName;
this.level = level;
this.city = city;
this.picture = picture;
this.pseudo = pseudo;
this.email = email;
this.password = password;
this.phone = phone;
this.dateOfBirth = dateOfBirth;
this.role = role;
}
public User(int user_id, String lastName, String firstName, Level level, String town) {
super();
this.user_id = user_id;
this.lastName = lastName;
this.firstName = firstName;
this.level = level;
this.city = town;
}
public long getUser_id() {
return user_id;
}
public void setUser_id(int user_id) {
this.user_id = user_id;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public Level getLevel() {
return level;
}
public void setLevel(Level level) {
this.level = level;
}
beikov
April 28, 2023, 6:50am
4
What does that mean exactly? Can you show some sample code with assertions that fail but shouldn’t? Don’t forget that if your table rows have null column values, they will be null in the Java objects as well. Some JSON serialization libraries omit attributes for null values.