Reputation: 41
Was testing my API to get a "Queue" by the ID and got the below error.
There was an unexpected error (type=Internal Server Error, status=500). Type definition error: [simple type, class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.example.ohramsbackend.model.Queue["patientQueue"]->com.example.ohramsbackend.model.Patient$HibernateProxy$dfNQ5Aj5["hibernateLazyInitializer"]) org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.example.ohramsbackend.model.Queue["patientQueue"]->com.example.ohramsbackend.model.Patient$HibernateProxy$dfNQ5Aj5["hibernateLazyInitializer"])
@Entity
@Table(name="queue")
public class Queue{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long queueId;
@Column(name="requestTime")
private LocalDateTime requestTime;
@Column(name="acceptTime")
private LocalDateTime acceptTime;
@Column(name="completeTime")
private LocalDateTime completeTime;
@Column(name="status")
private String status;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="icNumber")
private Patient patientQueue;
}
May I know why I can't get the Queue? Thanks in advance
Upvotes: 4
Views: 5780
Reputation: 303
I had the same problem.
You need to add @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
above the name of the class.
@Entity
@Table(name="queue")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Queue {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long queueId;
...
}
See this post to have more detail
Upvotes: 4