Here is my code. I would like to generate an automatic ID based on parent class. I'm using a method to create Airport, so my ID it's coming with is a null value. ID in AirportModel will be generated, but I don't know how to make it in child class.
@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;
Second class(child):
@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;
Third one(keys):
@Embeddable
public class AirportTranslatedModelKey implements Serializable {
@Column(name="airport_id")
private Long airportId;
@Column(name="language_code", length=2)
private String languageCode;
I still got the same errors; log:
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