I am trying to fix the error caused by the Hibernate query on my DB, but I can not find where the query is coming from. After turning on sqllog on hibernate, I found where the error is, but I don’t know how to fix it.
Hibernation request (eclipse log) "update students_classes set student_id = null where student_id =?"
throwing: ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-2) Column 'student_id' cannot be null
The error is displayed on this line:
student = studentDAO.save(student);
where the conservation comes from
public Entity save(Entity entity) throws Exception {
Entity result = null;
try {
trimAllStrAttributes(entity);
result = em.merge(entity);
} catch (Exception e) {
logger.error("Exception in AbstractDAO", e);
throw e;
}
return result;
}
private void trimAllStrAttributes(Entity product) throws IntrospectionException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
final Class c = product.getClass();
for (PropertyDescriptor propertyDescriptor : Introspector.getBeanInfo(c, Object.class).getPropertyDescriptors()) {
Method method = propertyDescriptor.getReadMethod();
if (method != null) {
String name = method.getName();
if (method.getReturnType().equals(String.class)) {
String property = (String) method.invoke(product);
if (property != null) {
try {
Method setter = c.getMethod("set" + name.substring(3), new Class<?>[] { String.class });
if (setter != null) {
setter.invoke(product, property.trim());
}
} catch (NoSuchMethodException nsme) {
}
}
}
}
}
}
This might be a display problem, so here are my entities:
Studentclasses
@Column(name = "student_id")
private Long studentId;
@Column(name = "classes_id")
private Long classesId;
Student
@AuditJoinTable
@ManyToMany
@JoinTable(name = "students_classes",
joinColumns = @JoinColumn(name = "student_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "classes_id", referencedColumnName = "id"))
private List<Classes> classes;
@NotAudited
@OneToMany
@JoinColumn(name = "student_id")
private List<StudentClasses> studentsClasses;
What should I do? Change a sleeping request (where to find it?) Or is there a problem at the matching level?