Create Table A ( ID varchar(8), Primary Key(ID) ); Create Table B ( ID varchar(8), A_ID varchar(8), Primary Key(ID), Foreign Key(A_ID) References A(ID) );
Given that I created two tables using the above SQL statements, and I want to create Entity classes for them, for class B I have these element attributes:
@Id @Column(name = "ID", nullable = false, length = 8) private String id; @JoinColumn(name = "A_ID", referencedColumnName = "ID", nullable = false) @ManyToOne(optional = false) private A AId;
In class A do I need to perform a mutual relationship?
@Id @Column(name = "ID", nullable = false, length = 8) private String id; @OneToMany(cascade = CascadeType.ALL, mappedBy = "AId") private List<B> BList;
Is it necessary or desirable to have a reverse @OneToMany for @ManyToOne ? If I make a design decision to leave the @OneToMany annotated attribute, will it come back to bite me again?
java orm jpa persistence
bguiz
source share