简体   繁体   English

无法确定类型:java.util.List,在表:file_post,列:[org.hibernate.mapping.Column(file)]

[英]Could not determine type for: java.util.List, at table: file_post, for columns: [org.hibernate.mapping.Column(file)]

i am try to store file image and some data in database but When running my application I ran into following error.我正在尝试将文件图像和一些数据存储在数据库中,但是在运行我的应用程序时,我遇到了以下错误。

error is:错误是:

Error creating bean with name 'filePostComtroller': Unsatisfied dependency expressed through field 'filePostService';创建名为 'filePostComtroller' 的 bean 时出错:通过字段 'filePostService' 表达的依赖关系不满足; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'filePostServiceImpl': Unsatisfied dependency expressed through field 'filePostDAO';嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“filePostServiceImpl”的 bean 时出错:通过字段“filePostDAO”表示不满足的依赖关系; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'filePostDAOImpl': Unsatisfied dependency expressed through field 'sessionFactory';嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为 'filePostDAOImpl' 的 bean 时出错:通过字段 'sessionFactory' 表达的依赖关系不满足; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/rms-servlet.xml]: Invocation of init method failed;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在 ServletContext 资源 [/WEB-INF/rms-servlet.xml] 中定义名称为“sessionFactory”的 bean 创建错误:调用 init 方法失败; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.List, at table: file_post, for columns: [org.hibernate.mapping.Column(file)]嵌套异常是 org.hibernate.MappingException:无法确定类型:java.util.List,在表:file_post,列:[org.ZCB1F008EEBF5012C4EF9A2C36E574]D.mapping.6

FilePost class:文件发布 class:

@Entity
@Table(name="file_post")
public class FilePost implements Serializable {

private static final long serialVersionUID = 74458L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="post_id")
private int postId;

@NotBlank
@Column(name="post_heading")
private String postHeading;

@NotBlank
@Column(name="post_description")
private String postDescription;


@Column(name="post_date")
private String postDate;

@Column(name="file")
private List<MultipartFile> file;


@ManyToOne(fetch=FetchType.LAZY, cascade= {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.DETACH,CascadeType.REFRESH })
@JoinColumn(name="user_username")
private User user;

public FilePost() {
    this.user = new User();
}

public FilePost(String postHeading, String postDescription, String postDate, List<MultipartFile> file, User user) {
    this.postHeading = postHeading;
    this.postDescription = postDescription;
    this.postDate = postDate;
    this.file = file;
    this.user = user;
}

public FilePost(int postId, String postHeading, String postDescription, String postDate, List<MultipartFile> file,
        User user) {
    this.postId = postId;
    this.postHeading = postHeading;
    this.postDescription = postDescription;
    this.postDate = postDate;
    this.file = file;
    this.user = user;
}

public int getPostId() {
    return postId;
}

public void setPostId(int postId) {
    this.postId = postId;
}

public String getPostHeading() {
    return postHeading;
}

public void setPostHeading(String postHeading) {
    this.postHeading = postHeading;
}

public String getPostDescription() {
    return postDescription;
}

public void setPostDescription(String postDescription) {
    this.postDescription = postDescription;
}

public String getPostDate() {
    return postDate;
}

public void setPostDate(String postDate) {
    this.postDate = postDate;
}

public User getUser() {
    return user;
}

public void setUser(User user) {
    this.user = user;
}

public List<MultipartFile> getFile() {
    return file;
}

public void setFile(List<MultipartFile> file) {
    this.file = file;
}

@Override
public String toString() {
    return "FilePost [postId=" + postId + ", postHeading=" + postHeading + ", postDescription=" + postDescription
            + ", postDate=" + postDate + ", file=" + file + "]";
}

FilePostComtroller:文件邮局控制器:

@Controller
public class FilePostComtroller {

@Autowired
private FilePostService filePostService;

@GetMapping("/showFilePostForm")
public String showFilePostForm(Model theModel) {
    FilePost theFilePost = new FilePost();
    theModel.addAttribute("filePost", theFilePost);
    return "filepost-form";
}

@PostMapping("/savePost")
public String uploadFole(@ModelAttribute("filePost") @Valid FilePost theFilePost, BindingResult theResult,
        Principal principal, HttpServletRequest servletRequest) {

    if (theResult.hasErrors()) {
        return "filepost-form";
    }

    //file 
    List<MultipartFile> files = theFilePost.getFile();
    List<String> fileNames = new ArrayList<String>();
    if (null != files && files.size() > 0) {
        for(MultipartFile multipartFile: files) {
            String fileName = multipartFile.getOriginalFilename();
            fileNames.add(fileName);

            File resourcesFile = new File(servletRequest.getServletContext().getRealPath("C:/Users/MD MITHU SARKER/eclipse-workspace/Resource-Management-System/WebContent/resources/file"), fileName);
            try {
                multipartFile.transferTo(resourcesFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    // get user name
    String username = principal.getName();
    theFilePost.getUser().setUserName(username);

    //save 
    filePostService.saveFilePost(theFilePost);

    return "filepost-form";
}

FilePostService:文件邮政服务:

public interface FilePostService {

void saveFilePost(FilePost theFilePost);

} }

FilePostServiceImpl: FilePostServiceImpl:

@Service
public class FilePostServiceImpl implements FilePostService {

@Autowired
private FilePostDAO filePostDAO;

@Override
@Transactional
public void saveFilePost(FilePost theFilePost) {
    filePostDAO.saveFilePost(theFilePost);

}

FilePostDAO:文件发布DAO:

public interface FilePostDAO {

void saveFilePost(FilePost theFilePost);

} }

FilePostDAOImpl: FilePostDAOImpl:

@Repository
public class FilePostDAOImpl implements FilePostDAO {

// need to inject the session factory
@Autowired
private SessionFactory sessionFactory;

@Override
public void saveFilePost(FilePost theFilePost) {
    Session currentSession = sessionFactory.getCurrentSession();

    currentSession.saveOrUpdate(theFilePost);
}

filepost-form.jsp filepost-form.jsp

<form:form action="savePost" modelAttribute="filePost" method="POST" enctype="multipart/form-data">

<label>Post Heading:</label><br>
<form:input type="text" path="postHeading" name="postHeading"/><br><br>
<form:errors path="postHeading"></form:errors>

<label>Post Description:</label><br>
<form:input type="text" path="postDescription" name="postDescription"/><br><br>
<form:errors path="postDescription"></form:errors>

<label>Post Date:</label><br>
<form:input type="date" path="postDate" name="postDate"/><br><br>
<form:errors path="postDate"></form:errors>

<label for="file">Post File: </label><br>
<form:input type="file" path="file" name="file" multiple="multiple"/><br><br>

<input type="submit" value="Submit"/>

</form:form>

You need to save the image as a blob in the database and declare it as a byte array byte[] in your entity您需要将图像保存为数据库中的blob ,并将其声明为实体中的字节数组byte[]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.hibernate.MappingException:无法确定类型:java.util.List,在表:大学,列:[org.hibernate.mapping.Column(students)] - org.hibernate.MappingException: Could not determine type for: java.util.List, at table: College, for columns: [org.hibernate.mapping.Column(students)] org.hibernate.MappingException:无法确定类型:java.util.List,在表:user处,用于列:[org.hibernate.mapping.Column(events)] - org.hibernate.MappingException: Could not determine type for: java.util.List, at table: user, for columns: [org.hibernate.mapping.Column(events)] org.hibernate.MappingException:无法确定类型:java.util.Set,在表:Company中,用于列:[org.hibernate.mapping.Column(users)] - org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: Company, for columns: [org.hibernate.mapping.Column(users)] org.hibernate.MappingException:无法确定类型:java.util.Collection,用于列:[org.hibernate.mapping.Column(lisOfAddresses)] - org.hibernate.MappingException: Could not determine type for: java.util.Collection, for columns: [org.hibernate.mapping.Column(lisOfAddresses)] org.hibernate.MappingException:无法确定以下类型:表:对于列:[org.hibernate.mapping.Column(plant) - org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(plant) 无法确定以下表的类型:org.json.JSONObject,在表:ordersinfo中,用于列:[org.hibernate.mapping.Column(items)] - Could not determine type for: org.json.JSONObject, at table: ordersinfo, for columns: [org.hibernate.mapping.Column(items)] 无法确定以下类型的字符串:字符串,在表:STUDENT,对于列:[org.hibernate.mapping.Column(SNAME)] - Could not determine type for: String, at table: STUDENT, for columns: [org.hibernate.mapping.Column(SNAME)] 无法确定类型 <DataType> 在表:TableX中,用于org.hibernate.mapping.Column(userPrefs)列 - could not determine type for <DataType> at table: TableX, for columns org.hibernate.mapping.Column(userPrefs) org.hibernate.MappingException:无法确定类型:java.util.List,在表:Schedule_assignedRoles,对于列:AssignedRoles - org.hibernate.MappingException: Could not determine type for: java.util.List, at table: Schedule_assignedRoles, for columns: assignedRoles 引起:org.hibernate.MappingException:无法确定类型:时间戳,列:[org.hibernate.mapping.Column(***)] - Caused by: org.hibernate.MappingException: Could not determine type for: Timestamp, for columns: [org.hibernate.mapping.Column(***)]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM