Note that there are some explanatory texts on larger screens.

plurals
  1. POID from parent to child in hibernate
    primarykey
    data
    text
    <p>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.</p> <pre><code>@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&lt;AirportTranslatedModel&gt; translations; </code></pre> <p>Second class(child):</p> <pre><code> @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; </code></pre> <p>Third one(keys):</p> <pre><code>@Embeddable public class AirportTranslatedModelKey implements Serializable { @Column(name="airport_id") private Long airportId; @Column(name="language_code", length=2) private String languageCode; </code></pre> <p>I still got the same errors; log:</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload