java - org.hibernate.MappingException : property mapping has wrong number of columns

标签 java spring postgresql hibernate many-to-one

我练习了 spring 框架和数据库(PostgreSQL),并且我得到了 IntelliJ (模块 JPA)的表,当我尝试运行时遇到了这个异常。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: property mapping has wrong number of columns: com.whoim.bootloader.entitys.TblConversation.tblUsersByCreatorIdConversation type: com.whoim.bootloader.entitys.TblUsers

我通过 IntelliJ(模块 JPA)上的持久性生成此代码并通过 Lombok 进行重构

package com.whoim.bootloader.entitys;

    import lombok.*;

    import javax.persistence.*;
    import java.sql.Timestamp;
    import java.util.Collection;

    @Data
    @Entity
    @Table(name = "tbl_conversation", schema = "public", catalog = "d1fu1ri15o3ia3")
    public class TblConversation {
        @Id@Column(name = "id_conversation")
        private int idConversation;
        @Basic@Column(name = "conversation_title")
        private String conversationTitle;
        @Basic@Column(name = "creator_id_conversation")
        private int creatorIdConversation;
        @Basic@Column(name = "conversation_channel_id")
        private String conversationChannelId;
        @Basic@Column(name = "conversation_created_at")
        private Timestamp conversationCreatedAt;
        @Basic@Column(name = "conversation_updated_at")
        private Timestamp conversationUpdatedAt;
        @Basic@Column(name = "conversation_deleted_at")
        private Timestamp conversationDeletedAt;

        @ManyToOne
        @JoinColumns({
                @JoinColumn(name = "creator_id_conversation", referencedColumnName = "id_user", nullable = false, insertable = true, updatable = true),
                @JoinColumn(name = "creator_id_conversation", referencedColumnName = "id_user", nullable = false)})
        private TblUsers tblUsersByCreatorIdConversation;

        @OneToMany(mappedBy = "tblConversationByDeletedConversationsConversationId")
        private Collection<TblDeletedConversations> tblDeletedConversationsByIdConversation;
        @OneToMany(mappedBy = "tblConversationByConversationIdMessages")
        private Collection<TblMessages> tblMessagesByIdConversation;
        @OneToMany(mappedBy = "tblConversationByConversationIdParticipants")
        private Collection<TblParticipants> tblParticipantsByIdConversation;

    }

最佳答案

我认为根据标准,您的映射应该如下:

    @Basic@Column(name = "creator_id_conversation", insertable=false, updatable=false)
    private int creatorIdConversation;

    @ManyToOne
    @JoinColumn(name = "creator_id_conversation"
              , referencedColumnName = "id_user", nullable = false)})
    private TblUsers tblUsersByCreatorIdConversation;

关于java - org.hibernate.MappingException : property mapping has wrong number of columns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56046295/

相关文章:

java - 在 Datatable JSF 中显示 Set 集合中的对象不起作用

java - 如何使用作业参数替换从文件加载 bean 值?

java - 由: org. springframework.beans.PropertyBatchUpdateException : Could not load JDBC driver class [oracle. jdbc.driver.OracleDriver引起]

postgresql - 如何从 PostgreSQL 中的函数访问外部作用域变量?

linux - 内部服务器错误odoo

java - 应用OOP聚合概念的正确方法

java.sql.SQLException : Parameter index out of range (3 > number of parameters, 这是 2)

java - 如何在运行时获取路径java源代码?

java - 当我的服务层位于另一个模块中时,如何获得注释之类的支持?

python - 如何正确使用 SQL LIKE 语句从 Flask 应用程序查询数据库