How to find / change hibernation request

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 the current level of Property is of type String
                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?

+4
3

:

throwing: ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-2) 'student_id' null

, studentId , , , , , :

studentId id :

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long studentId;

Hibernate :

  • AUTO - ,
  • -
  • -
  • -
  • -
+2

StudentId. .

  • , .

      CREATE SEQUENCE STUDENT_SEQ
      MINVALUE 1
      MAXVALUE 999999999999999999999999999
      START WITH 1
      INCREMENT BY 1
      CACHE 20;
    
  • .

      @Id
      @SequenceGenerator(name = "StudentSeq", sequenceName="STUDENT_SEQ", allocationSize=1)
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "StudentSeq")
      @Column(name = "Student_id", nullable = false)
      private Long StudentId;
    
+1

,

result = em.merge(entity);

entity set studentId, . , .

0

All Articles