繁体   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)]

我正在尝试将文件图像和一些数据存储在数据库中,但是在运行我的应用程序时,我遇到了以下错误。

错误是:

创建名为 'filePostComtroller' 的 bean 时出错:通过字段 'filePostService' 表达的依赖关系不满足; 嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“filePostServiceImpl”的 bean 时出错:通过字段“filePostDAO”表示不满足的依赖关系; 嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为 'filePostDAOImpl' 的 bean 时出错:通过字段 'sessionFactory' 表达的依赖关系不满足; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:在 ServletContext 资源 [/WEB-INF/rms-servlet.xml] 中定义名称为“sessionFactory”的 bean 创建错误:调用 init 方法失败; 嵌套异常是 org.hibernate.MappingException:无法确定类型:java.util.List,在表:file_post,列:[org.ZCB1F008EEBF5012C4EF9A2C36E574]D.mapping.6

文件发布 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 + "]";
}

文件邮局控制器:

@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";
}

文件邮政服务:

public interface FilePostService {

void saveFilePost(FilePost theFilePost);

}

FilePostServiceImpl:

@Service
public class FilePostServiceImpl implements FilePostService {

@Autowired
private FilePostDAO filePostDAO;

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

}

文件发布DAO:

public interface FilePostDAO {

void saveFilePost(FilePost theFilePost);

}

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

<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>

您需要将图像保存为数据库中的blob ,并将其声明为实体中的字节数组byte[]

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM