Spring
和PostgreSQL
之间的“通信”出现问题。
我的班级User.java
:
public static final String TABLE_NAME = "USERS";
public static final String SEQENCE = "USERS_SEQ";
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SEQENCE)
@SequenceGenerator(name = SEQENCE, sequenceName = SEQENCE, allocationSize = 1)
private Long userId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "department_id")
private Department department;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "organizazion_id")
private Organization organization;
为USERS
创建表脚本:
CREATE TABLE IF NOT EXISTS USERS (
USER_ID BIGINT NOT NULL,
DEPARTMENT_ID BIGINT,
ORGANIZATION_ID BIGINT,
PRIMARY KEY (USER_ID),
FOREIGN KEY (DEPARTMENT_ID) REFERENCES DEPARTMENT(DEPARTMENT_ID),
FOREIGN KEY (ORGANIZATION_ID) REFERENCES ORGANIZATION(ORGANIZATION_ID)
);
等级Department.java
public static final String TABLE_NAME = "DEPARTMENT";
public static final String SEQENCE = "DEPARTMENT_SEQ";
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SEQENCE)
@SequenceGenerator(name = SEQENCE, sequenceName = SEQENCE, allocationSize = 1)
private Long departmentId;
private String departmentName;
.
.
. //Some other columns of primitive types about department..
为DEPARTMENT
创建表脚本:
CREATE TABLE IF NOT EXISTS DEPARTMENT (
DEPARTMENT_ID BIGINT NOT NULL,
DEPARTMENT_NAME VARCHAR(50),
PRIMARY KEY (DEPARTMENT_ID)
);
Organization.java
public static final String TABLE_NAME = "ORGANIZATION";
public static final String SEQENCE = "ORGANIZATION_SEQ";
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SEQENCE)
@SequenceGenerator(name = SEQENCE, sequenceName = SEQENCE, allocationSize = 1)
private Long organizationId;
private String organizationName;
private String street;
private String postalCode;
private String state;
private String city;
为ORGANIZATION
创建表脚本:
CREATE TABLE IF NOT EXISTS ORGANIZATION (
ORGANIZATION_ID BIGINT NOT NULL,
ORGANIZATION_NAME VARCHAR(50),
STREET VARCHAR(255),
POSTAL_CODE VARCHAR(50),
STATE VARCHAR(255),
CITY VARCHAR(255),
PRIMARY KEY (ORGANIZATION_ID)
);
当我运行程序时,Spring
在PostgreSQL
中创建“自己的”列,它看起来像:
USER_ID, DEPARTMENT_ID, ORGANIZATION_ID, DEPARTMENT_DEPARTMENT_ID, ORGANIZATION_ORGANIZATION_ID
怎么修?应该是没有柱子的
DEPARTMENT_DEPARTMENT_ID, ORGANIZATION_ORGANIZATION_ID
此处不能使用注解@Column(name = "column_name")
。
1条答案
按热度按时间3phpmpom1#
作为连接列,您应该引用其他类中的属性: