Answer the question
In order to leave comments, you need to log in
Hibernate feedback - null?
Hello, I have been struggling with a problem for a long time, about which they write a lot, it googles well, but in my case it is not solved for some reason.
@Entity
@Table(name = EVENT_CLASS_FAMILY_TABLE_NAME)
public class EventClassFamily extends GenericModel<EventClassFamilyDto> {
private static final long serialVersionUID = 3766947955702551264L;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = EVENT_CLASS_FAMILY_VERSION_EVENT_CLASS_FAMILY_ID, nullable = false)
private List<EventClassFamilyVersion> schemas;
@Entity
@Table(name = EVENT_CLASS_FAMILY_VERSION_TABLE_NAME)
public class EventClassFamilyVersion extends GenericModel<EventClassFamilyVersionDto> {
private static final long serialVersionUID = -7490111487256831990L;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "ecfv")
//@OneToMany(cascade = CascadeType.ALL)
//@JoinColumn(name = EVENT_CLASS_EVENT_CLASS_FAMILY_VERSION_ID, nullable = false)
private List<EventClass> records;
@Entity
@Table(name = EVENT_CLASS_TABLE_NAME)
public class EventClass extends GenericModel<EventClassDto> {
private static final long serialVersionUID = 3766947955702551264L;
@ManyToOne
@JoinColumn(name = EVENT_CLASS_TENANT_ID, nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Tenant tenant;
@ManyToOne(cascade = CascadeType.ALL)
// @OnDelete(action = OnDeleteAction.CASCADE)
private EventClassFamilyVersion ecfv;
Answer the question
In order to leave comments, you need to log in
To get sets of related objects (@OneToMany and @ManyToMany) you need to specify fetch=FetchType.EAGER in the link annotation. This is convenient, but there is a pitfall - the number of queries to the database will increase, just like the amount of data transferred.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question