Could not determine recommended JdbcType for `java.util.Map<java.lang.String, java.lang.String>
Error:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'entityManagerFactory' defined in class path
resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:
Could not determine recommended JdbcType for `java.util.Map<java.lang.String, java.lang.String>`
The mentioned error will occur when attempting to create a model using the following code:
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String firstName;
private String lastName;
private Map<String,String> stdentDetails;
private String city;
private Date joinDate;
}
The error message here is related to Spring and Hibernate when trying to create an entityManagerFactory
. The issue seems to be with determining the recommended JdbcType
for a java.util.Map<java.lang.String, java.lang.String>
i.e studentDetails variable.
Solution:
To resolve this issue, include the annotation @JdbcTypeCode(SqlTypes.JSON) on the ‘studentDetails’ variable as shown below:
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String firstName;
private String lastName;
@JdbcTypeCode(SqlTypes.JSON)
private Map<String,String> stdentDetails;
private String city;
private Date joinDate;
}