Back again!
Sorry about this.
Okay, I have a two entities: Volume and Issue
The Volume contains a load of issues, and I’ve created a screen that allows me to create volumes and add issues on the same page.
When I hit the Ok button, I get this:
I’ve set up the issues as a nested data source inside the Volume data source, and I’ve set up the volume entity as containing a list of issues.
If I save the Volume first, AND THEN add the issues afterwards, then it’s fine, so I guess the problem is the order in which things are being saved?
volume.java
@NamePattern("%s |name")
@Table(name = "PEER_VOLUME")
@Entity(name = "peer$Volume")
public class Volume extends StandardEntity {
private static final long serialVersionUID = 7001842511820670442L;
@CaseConversion
@Column(name = "ISBN", length = 60)
protected String isbn;
@Column(name = "NAME", length = 100)
protected String name;
@Column(name = "YEAR_OF_PUBLICATION")
@NumberFormat(pattern = "#")
protected Long yearOfPublication;
@Lob
@Column(name = "DESCRIPTION", nullable = false)
protected String description;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "JOURNAL_ID")
protected Journal journal;
@OnDelete(DeletePolicy.CASCADE)
@Composition
@OneToMany(mappedBy = "volume")
protected List<Issue> issues;
public void setIssues(List<Issue> issues) {
this.issues = issues;
}
public List<Issue> getIssues() {
return issues;
}
public void setJournal(Journal journal) {
this.journal = journal;
}
public Journal getJournal() {
return journal;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getIsbn() {
return isbn;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setYearOfPublication(Long yearOfPublication) {
this.yearOfPublication = yearOfPublication;
}
public Long getYearOfPublication() {
return yearOfPublication;
}
}
issue.java
@NamePattern("%s %s|issueNumber,issueName")
@Table(name = "PEER_ISSUE")
@Entity(name = "peer$Issue")
public class Issue extends StandardEntity {
private static final long serialVersionUID = 6106725923937344229L;
@Column(name = "ISSUE_NUMBER", length = 60)
protected String issueNumber;
@Column(name = "ISSUE_NAME", length = 60)
protected String issueName;
@Lob
@Column(name = "DESCRIPTION")
protected String description;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "VOLUME_ID")
protected Volume volume;
public void setVolume(Volume volume) {
this.volume = volume;
}
public Volume getVolume() {
return volume;
}
public void setIssueNumber(String issueNumber) {
this.issueNumber = issueNumber;
}
public String getIssueNumber() {
return issueNumber;
}
public void setIssueName(String issueName) {
this.issueName = issueName;
}
public String getIssueName() {
return issueName;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
… and the view setup
<dsContext>
<datasource id="volumeDs"
class="com.peer.entity.Volume"
view="volume-view">
<collectionDatasource id="issuesDs"
property="issues"/>
</datasource>
</dsContext>
I’ve had a look through a couple of forum entries with similar problems, but I can’t see what I’ve missed!