[英]How to store a List of a class object into MySql using Spring boot
I want to store a List of class : RestApiResponse into MySql.我想将类列表:RestApiResponse 存储到 MySql 中。 But getting below error:
但得到以下错误:
org.hibernate.HibernateException: Could not determine a type for class: com.try.sreapi.beans.RestApiResponse
Below are my classes:下面是我的课:
Entity class : SREAPITestingHistory.java实体类:SREAPITestingHistory.java
@NamedQueries(@NamedQuery(name="getSREAPITestHistory.findAll", query="SELECT a FROM SREAPITestingHistory a"))
@SqlResultSetMapping(name="sreapitestinghistoryres",
entities=@EntityResult(entityClass=SREAPITestingHistory.class))
@Entity
@Table(name="sreapi_testing_history_details")
@Transactional
public class SREAPITestingHistory implements Serializable{
private static final long serialVersionUID = -7221709766109001257L;
@Id
@Column(name="request_time")
private String request_time;
@Column(name="req_id")
private String req_id;
@Column(name="app_name")
private String app_name;
@Column(name="request_name")
private String request_name;
@Lob
@Column(name="response_body")
private List<RestApiResponse> response;
public String getRequest_time() {
return request_time;
}
public void setRequest_time(String request_time) {
this.request_time = request_time;
}
public String getReq_id() {
return req_id;
}
public void setReq_id(String req_id) {
this.req_id = req_id;
}
public String getApp_name() {
return app_name;
}
public void setApp_name(String app_name) {
this.app_name = app_name;
}
public String getRequest_name() {
return request_name;
}
public void setRequest_name(String request_name) {
this.request_name = request_name;
}
public List<RestApiResponse> getResponse() {
return response;
}
public void setResponse(List<RestApiResponse> response) {
this.response = response;
}
}
Repository Class: SREAPITestingRepository.java存储库类:SREAPITestingRepository.java
@Repository
public interface SREAPITestingRepository extends CrudRepository< SREAPITestingHistory, String> {
@Modifying
@Transactional
@Query(value="INSERT into sreapi_testing_history_details (request_time,req_id,app_name,request_name,response_body)"+ "VALUES (:request_time,:req_id,:app_name,:request_name,:response_body)", nativeQuery = true)
public void setApiTestHistoryDetails(@Param("request_time") String request_time,@Param("req_id") String req_id,@Param("app_name") String app_name,@Param("request_name") String request_name,@Param("response_body") List<RestApiResponse> response_body);
}
When I am trying to add values for response_body which is actually a List of RestApiResponse class and I am getting Could not determine a type for class: com.try.sreapi.beans.RestApiResponse exception当我尝试为 response_body 添加值时,它实际上是 RestApiResponse 类的列表,并且我得到了无法确定类的类型:com.try.sreapi.beans.RestApiResponse 异常
A Lob may be either a binary or character type.
Lob 可以是二进制或字符类型。
The Lob type is inferred from the type of the persistent field or property, and except for string and character-based types defaults to Blob.
Lob 类型是从持久字段或属性的类型推断出来的,除字符串和基于字符的类型外,默认为 Blob。
Example 1:
示例 1:
@Lob @Basic(fetch=LAZY) @Column(name="REPORT")
@Lob @Basic(fetch=LAZY) @Column(name="REPORT")
String report;字符串报告;
Example 2:
示例 2:
@Lob @Basic(fetch=LAZY) @Column(name="EMP_PIC", columnDefinition="BLOB NOT NULL") protected byte[] pic;
@Lob @Basic(fetch=LAZY) @Column(name="EMP_PIC", columnDefinition="BLOB NOT NULL") protected byte[] pic;
So you can convert your list of data into json string or bytes to store.因此,您可以将数据列表转换为要存储的 json 字符串或字节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.