这是我的代码。我想根据父类生成一个自动 ID。我正在使用一种方法来创建机场,所以它附带的我的 ID 是一个空值。将生成 AirportModel 中的 ID,但我不知道如何在子类中生成它。
@Entity(name = "Airport")
@Table(name = "ai_airport")
public class AirportModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "airport_id")
private List<AirportTranslatedModel> translations;
二等(儿童):
@Entity(name = "AirportTranslated")
@IdClass(AirportTranslatedModelKey.class)
@Table(name = "ai_translated_airport")
public class AirportTranslatedModel
@Id
@Column(name="airport_id")
private Long airportId;
@Id
@Column(name="language_code", length=2)
private String languageCode;
第三个(键):
@Embeddable
public class AirportTranslatedModelKey implements Serializable {
@Column(name="airport_id")
private Long airportId;
@Column(name="language_code", length=2)
private String languageCode;
我仍然遇到同样的错误;日志:
Hibernate: insert into ai_airport (active, airport_code, city_code, country_code, externa
l_id, is_default, latitude, longitude, market_code, min_connection_time_DD, min_connection_time_DI, min_connection_time_id, min_connection_time_II, time_diff, VERSION) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into ai_translated_airport (airport_long_name, airport_short_name, airp
ort_id, language_code) values (?, ?, ?, ?)
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Column 'airport_id' cannot be null