import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
//import javax.persistence.NamedNativeQueries;
//import javax.persistence.NamedNativeQuery;
//import javax.persistence.NamedQueries;
@Column(name="id", updatable=false, nullable=false)
private Long id;
-// 1. Using just OneToMany:
-// @OneToMany(mappedBy="ad", fetch=FetchType.LAZY,
-// cascade = CascadeType.ALL, targetEntity=AdDescription.class)
-// 2. The same using @OneToMany + @JoinTable:
- @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, targetEntity=AdDescription.class)
- @JoinTable(
- name="ad_description",
- joinColumns = @JoinColumn( name="id"),
- inverseJoinColumns = @JoinColumn( name="ad_id")
- )
+ @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
+ @JoinColumn(name = "ad_id", nullable = false)
private Set<AdDescription> adDescriptions;
@Max(60)
this.updatedAt = updatedAt;
}
+ /**
+ * WARNING: JPA REQUIRES GETTERS!!!
+ */
+
public Long getId() {
return id;
}
@Column(name="id", updatable=false, nullable=false)
private Long id;
- @ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL, optional=false)
- @JoinColumn(name="ad_id", referencedColumnName="id")
+ @ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL, optional=true)
+ @JoinColumn(name="ad_id", nullable=false, updatable = false, insertable = false, referencedColumnName="id")
private Ad ad;
@NotNull
this.adMobileText = adMobileText;
this.adLink = adLink;
}
+
+ /**
+ * WARNING: JPA REQUIRES GETTERS!!!
+ */
public Long getId() {
return id;