javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize

前端 未结 6 1300
Happy的楠姐
Happy的楠姐 2021-02-19 04:32

When executing a Criteria Query in hibernate, I get the following exception:

javax.persistence.PersistenceException: javax.persistence.PersistenceException: org.         


        
6条回答
  •  眼角桃花
    2021-02-19 05:09

    I had the same problem. It was due to an enum in a @SqlResultSetMapping. The solution is here: @ConstructorResult with Enum in JPA 2.1

    Edit, due to a comment from @Eugene Mihaylin:
    So, I had the following situation:

        @SqlResultSetMapping(
        name = "MyTargetClassMappingName",
        classes = {
                @ConstructorResult(
                        targetClass = MyTargetClassDTO.class,
                        columns = {
                                @ColumnResult(name = "name_from_query1"),
                                @ColumnResult(name = "name_from_query2"),
                                ...
                                @ColumnResult(name = "name_of_problematic_column", type = MyCustomEnum.class),
                        }
                )
        })
        @Entity
        public class MyTargetClassDTO ...
    

    And I needed to change to:

        @SqlResultSetMapping(
        name = "MyTargetClassMappingName",
        classes = {
                @ConstructorResult(
                        targetClass = MyTargetClassDTO.class,
                        columns = {
                                @ColumnResult(name = "name_from_query1"),
                                @ColumnResult(name = "name_from_query2"),
                                ...
                                @ColumnResult(name = "name_of_problematic_column", type = String.class),
                        }
                )
        })
        @Entity
        public class MyTargetClassDTO ...
    

    in order to fix the issue.

    Later, in the constructor of the DTO (annotated as @Entity), I am doing: MyCustomEnum.valueOf(...) in order to parse the value of the string and assign it to the specified field of type MyCustomEnum in the DTO.

提交回复
热议问题