views:

38

answers:

2

Hi guys,

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 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

A: 
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
    @JoinColumn(name="caseId")  

Try this

org.life.java
Thanks, I tried it out, but unfortunately no change, still only one document returned, and thereafter two documents. Very strange indeed
niklassaers
+2  A: 

The mapping looks correct. But it would be interesting to see:

  • the Document entity (and its equals/hashCode)
  • the SQL performed (see this previous answer to activate SQL logging)
Pascal Thivent
Dear sir! You are my personal hero today!!! :-) Thanks for the hint of hashCode, I had been thinking of it before, but come away from it. Regenerating it in STS made it tick like it should! :-)
niklassaers
Grt.!!9 more to go..
org.life.java
@niklassaers Glad it's solved. @org.life.java Hmm... what? :)
Pascal Thivent
Its great of you Pascal
org.life.java