import java.time.OffsetDateTime;
import java.util.Set;
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
@Column(name="id", updatable=false, nullable=false)
private Long id;
- @OneToMany(mappedBy="ad", fetch=FetchType.LAZY, targetEntity=AdDescription.class)
+ @OneToMany(mappedBy="ad", fetch=FetchType.LAZY,
+ cascade = CascadeType.ALL, targetEntity=AdDescription.class)
private Set<AdDescription> adDescriptions;
@Max(60)
}
// It will be used by my code (for example by Unit Tests)
- public Ad(Long id, Long companyId, Long companyCategId, String adMobileImage, OffsetDateTime createdAt,
- OffsetDateTime updatedAt) {
+ public Ad(Long id, Set<AdDescription> adDescriptions, Long companyId, Long companyCategId, String adMobileImage,
+ OffsetDateTime createdAt, OffsetDateTime updatedAt) {
this.id = id;
+ this.adDescriptions = adDescriptions;
+ this.companyId = companyId;
this.companyCategId = companyCategId;
this.adMobileImage = adMobileImage;
this.createdAt = createdAt;
return id;
}
+ public Set<AdDescription> getAdDescriptions() {
+ return adDescriptions;
+ }
+
public Long getCompanyId() {
return companyId;
}
import java.io.Serializable;
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
-import de.spring.example.persistence.domain.Ad;
-
@Entity
@Table(name="ad_description", schema="mybatis_example")
public class AdDescription implements Serializable {
@Column(name="id", updatable=false, nullable=false)
private Long id;
- @NotNull
- @ManyToOne(optional=false)
+ @ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL, optional=false)
@JoinColumn(name="ad_id", referencedColumnName="id")
private Ad ad;
@NotNull
@Max(60)
- @Column(name="language_id")
+ @Column(name="laguage_id")
private Long languageId;
@NotNull
public AdDescription(Long id, Ad ad, Long languageId, String adName, String adDescription,
String adMobileText, String adLink) {
this.id = id;
- this.languageId = languageId;
this.ad = ad;
+ this.languageId = languageId;
this.adName = adName;
this.adDescription = adDescription;
this.adMobileText = adMobileText;
*/
public interface AdDescriptionRepository extends PagingAndSortingRepository<AdDescription, Long> {
- // Custom Query method
+ // Custom Query method (useful when the offered methods by PagingAndSortingRepository are not enough)
Page<AdDescription> findByAd(Ad ad, Pageable pageable);
}