Could not determine type for: org.springframework.web.multipart.MultipartFile

An error is reported when SpringBoot starts:

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: org.springframework.web.multipart.MultipartFile, at table: attachment, for columns: [org.hibernate.mapping.Column(file)]

The reason is that there is an entity class that defines a file variable with the MultipartFile type. The original intention is to store files. The code is as follows:

/**
 * file
 */
@Column(nullable = false)
private MultipartFile file;

Focus on this sentence here:

Could not determine type for: org.springframework.web.multipart.MultipartFile

This means that when the table is automatically built, the compiler cannot determine what type of MultipartFile should correspond to in the database, and the file is stored in binary in the database, so the code of the entity class is slightly modified:

/**
 * file
 */
@Column(nullable = false,columnDefinition = "MediumBlob")
private byte[] file;

Then start, the problem is solved.

tips:

MySQL's four BLOB types

Type size (unit: bytes)
TinyBlob max 255
Blob max 65K
MediumBlob max 16M
LongBlob max 4G

Guess you like

Origin blog.csdn.net/qq_42026590/article/details/110865304