I need help to define correctly a @OneToMany JPA annotation. Tried different ways but still get error/issues like the foreign key (visitor_revision_id) is null in the visitorCharacteristic table.
I would like to join the 2 tables with the "visitor_revision_id"
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
@ToString
public class Visitor {
@Id
@Column(name="visitor_revision_id")
@GeneratedValue(strategy= GenerationType.IDENTITY)
Long id;
String visitorCode;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "visitor")
List<VisitorCharacteristic> visitorCharacteristicList;
}
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
@ToString
class VisitorCharacteristic {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
Long id;
@JoinColumn(name = "visitor_revision_id")
@ManyToOne(optional = false) //fetch = FetchType.EAGER, cascade = CascadeType.ALL)
Visitor visitor;
@Column(nullable = false)
String attributeCode;
@Column(nullable = false)
String attributeValue;
}
Thanks in advance for your help
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…