com.sun.jdi.InvocationException occurred invoking method

前端 未结 16 1220
迷失自我
迷失自我 2020-12-13 01:38

I just want to create an object of class, but got this error when debugging. Can anybody tell me what the problem is? The location of this code is in some Spring(2.5) Servic

相关标签:
16条回答
  • 2020-12-13 01:54

    I have received com.sun.jdi.InvocationException occurred invoking method when I lazy loaded entity field which used secondary database config (Spring Boot with 2 database configs - lazy loading with second config does not work). Temporary solution was to add FetchType.EAGER.

    0 讨论(0)
  • 2020-12-13 01:57

    For me the same exception was thrown when the toString was defined as such:

    @Override
    public String toString() {
        return "ListElem [next=" + next + ", data=" + data + "]";
    }
    

    Where ListElem is a linked list element and I created a ListElem as such:

    private ListElem<Integer> cyclicLinkedList = new ListElem<>(3);
    ListElem<Integer> cyclicObj = new ListElem<>(4);
    ...
    
    cyclicLinkedList.setNext(new ListElem<Integer>(2)).setNext(cyclicObj)
        .setNext(new ListElem<Integer>(6)).setNext(new ListElem<Integer>(2)).setNext(cyclicObj);
    

    This effectively caused a cyclic linked list that cannot be printed. Thanks for the pointer.

    0 讨论(0)
  • 2020-12-13 02:00

    I had the same issue once. In my case toString() method was badly created. TO be precise a static final variable was included in the toString method when a developer form my team was assigned code cleaning task and to add toString(), hashCode() code and equals() methods to domain objects where ever possible. but in of the classes because of over looking at it, he included final static variable that caused the "com.sun.jdi.InvocationException" this exception was visible on debugging only when I hovered over the object which has the exception.

    0 讨论(0)
  • 2020-12-13 02:00

    This was my case

    I had a entity Student which was having many-to-one relation with another entity Classes (the classes which he studied).

    I wanted to save the data into another table, which was having foreign keys of both Student and Classes. At some instance of execution, I was bringing a List of Students under some conditions, and each Student will have a reference of Classes class.

    Sample code :-

    Iterator<Student> itr = studentId.iterator();
    while (itr.hasNext()) 
    {
        Student student = (Student) itr.next();
        MarksCardSiNoGen bo = new MarksCardSiNoGen();
    
        bo.setStudentId(student);
    
        Classes classBo = student.getClasses();
    
        bo.setClassId(classBo);
    }
    

    Here you can see that, I'm setting both Student and Classes reference to the BO I want to save. But while debugging when I inspected student.getClasses() it was showing this exception(com.sun.jdi.InvocationException).

    The problem I found was that, after fetching the Student list using HQL query, I was flushing and closing the session. When I removed that session.close(); statement the problem was solved.

    The session was closed when I finally saved all the data into table(MarksCardSiNoGen).

    Hope this helps.

    0 讨论(0)
  • 2020-12-13 02:03

    I was facing the same issue because I was using Lombok @Data annotation that was creating toString and hashcode methods in class files, so I removed @Data annotation and used specific @Gettter @Setter annotation that fixed my issue.

    we should use @Data only when we need all @ToString, @EqualsAndHashCode, @Getter on all fields, and @Setter on all non-final fields, and @RequiredArgsConstructor.

    0 讨论(0)
  • 2020-12-13 02:05

    so I had same problem here. Found out that my domain instance was getting detached from the hibernate session. I used isAttached() to check and attached the domain using d.attach()

    0 讨论(0)
提交回复
热议问题