完整的错误消息如下:
Unable to create unique key constraint (aircraft_series_id, service_enum) on table aircraft_service: database column 'service_enum' not found. Make sure that you use the correct column name which depends on the naming strategy in use (it may not be the same as the property name in the entity, especially for relational types)
我的实体被指定为:
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "aircraft_series_id", "service_enum" }) })
@Getter
@Setter
@NoArgsConstructor
@ToString
public class AircraftService {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
private Integer minimumQuantity;
@NotNull
private Integer maximumQuantity;
@NotNull
private Integer defaultQuantity;
@NotNull
@ManyToOne(optional = false)
@JsonIgnore
private AircraftSeries aircraftSeries;
@NotNull
@Enumerated(EnumType.STRING)
private ServiceEnum serviceEnum;
}
如果我注解掉@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "aircraft_series_id", "service_enum" }) })
注解,则会创建列,并且在SQL客户端下打开表时可以看到字段名。
service_enum
aircraft_series_id
现在,我正在对H2数据库运行应用程序。
1条答案
按热度按时间qlvxas9a1#
我可以让应用程序在运行时不抛出异常,如果类正在吹嘘列注解,如下所示:
我不明白为什么会这样,因为在默认情况下,当应用程序本身赋予列名属性时,列名完全相同。