@Entity
@Table(name = "artist")
public class Artist implements java.io.Serializable{
@Basic
@Column(name = "is_active",nullable=false)
private Boolean isActive = false;
@OneToMany(mappedBy = "artist", cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
private Set<Project> projects= new HashSet<Project>();
}
and
@Entity
@Table(name = "project")
public class Project implements java.io.Serializable{
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "artist_id")
private Artist artist;
@Basic
@Column(name = "is_active",nullable=false)
private Boolean isActive = false;
}
Can I initialize isActive in Project like following with the intent that Project‘s flag gets initialized by Artist‘s flag
private Boolean isActive = ((getArtist()!=null)? getArtist().getIsActive(): false);
Will the order in which the members are defined in Project can cause isActive to be false always?
with that declaration:
the isActive will always be false because both artist and isActive will be initialized before the default constructor for Project. So artist is initialized to null, then isActive is initialized to false (because getArtist() is null), then the default constructor for Project runs (but the constructor does nothing), so isActive is always false.