I've got an entity Case that has an id CaseId (unfortunately a string due to compability with a legacy system). This id is foreign key in the table Document, and each Case c开发者_如何学Can have many documents (onetomany). I've put the following in my Case entity:
@Id
@Column(name = "CaseId", length = 20, nullable = false)
private String caseId;
@OneToMany(fetch=FetchType.EAGER)
@JoinColumns ( {
@JoinColumn(name="caseId", referencedColumnName="CaseId")
} )
private Set<Document> documents;
The table for Document contains "CaseId varchar(20) not null". Right now, in the database, all cases have six documents. Yet when I do myCase.documents().size, I only ever get a single document. What should I do to get all the documents?
Cheers
Nik
The mapping looks correct. But it would be interesting to see:
- the
Document
entity (and itsequals
/hashCode
) - the SQL performed (see this previous answer to activate SQL logging)
精彩评论