Java Hibernate JoinTable错误:找不到具有逻辑名称的列

Java Hibernate JoinTable错误:找不到具有逻辑名称的列,java,hibernate,hibernate-mapping,psql,Java,Hibernate,Hibernate Mapping,Psql,我正在尝试通过hibernate中的JoinTable进行单向多通关联,但我一直遇到以下错误: A JPA error occurred (Unable to build EntityManagerFactory): Unable to find column with logical name: name in org.hibernate.mapping.Table(users) and its related supertables and secondary tables 我有3个模型房

我正在尝试通过hibernate中的JoinTable进行单向多通关联,但我一直遇到以下错误:

A JPA error occurred (Unable to build EntityManagerFactory): Unable to find column with logical name: name in org.hibernate.mapping.Table(users) and its related supertables and secondary tables
我有3个模型房屋,用户,用户房屋地图。我希望能够通过UserHouseMap访问用户住宅。这是用户的映射

出于其他原因,我需要通过不是主键的列将用户映射到UserHouseMap

@Id
@GeneratedValue
@Expose
public Long id;

@Expose
@Required
@ManyToOne
@JoinTable(name = "user_house_map",
        joinColumns= {@JoinColumn(table="users", name="user_name", referencedColumnName="name")},
        inverseJoinColumns={@JoinColumn(table="houses", name="house_name", referencedColumnName="house_name")})
public House house;
以下是所有3个模型的DB模式

使用者

房屋

用户房屋地图

从JoinColumn注释中删除table=用户和table=房屋

此属性不应包含外键的目标表。它仅在一个实体映射到两个表时使用,以便判断联接列位于哪个表中

此外,您的表定义非常奇怪:

join表应该有两个外键:一个引用users表的PK,另一个引用house表的PK。为什么引用用户的名称而不是其ID? users.name上的外键约束没有意义。
我认为这是因为您将用户pkey定义为id,并试图将其与user_name连接,因此错误bigint=character variaging请尝试从id字段中删除注释@id,然后查看结果happens@JorgeCampos您是对的,所以我将映射更改为使用referenceColumn。检查我的更新错误
                               Table "public.users"
        Column         |            Type             |          Modifiers          
-----------------------+-----------------------------+-----------------------------
 name                  | character varying(255)      |
 id                    | integer                     | not null 
Indexes:
    "user_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "housing_fkey" FOREIGN KEY (name) REFERENCES user_house_map(user_name) DEFERRABLE INITIALLY DEFERRED
                Table "public.houses"
    Column     |          Type          | Modifiers 
---------------+------------------------+-----------
 house_name    | character varying(255) | not null
 address       | text                   | 
 city          | text                   | 
 state         | text                   | 
 zip           | integer                | 
 zip_ext       | integer                | 
 phone         | text                   | 
Indexes:
    "house_pkey" PRIMARY KEY, btree (house_name)
Referenced by:
    TABLE "user_house_map" CONSTRAINT "house_map_fkey" FOREIGN KEY (house_name) REFERENCES house(house_name) DEFERRABLE INITIALLY DEFERRED
         Table "public.user_house_map"
   Column    |          Type          | Modifiers 
-------------+------------------------+-----------
 user_name   | character varying(255) | not null
 house_name  | character varying(255) | not null
Indexes:
    "user_house_map_pkey" PRIMARY KEY, btree (user_name)
    "user_house_map_house_key" btree (house_name)
Foreign-key constraints:
    "user_house_map_house_fkey" FOREIGN KEY (house_name) REFERENCES houses(house_name) DEFERRABLE INITIALLY DEFERRED
Referenced by:
    TABLE "users" CONSTRAINT "housing_fkey" FOREIGN KEY (name) REFERENCES user_house_map(user_name) DEFERRABLE INITIALLY DEFERRED