Vishal
Vishal

Reputation: 1414

Eager loading at Collection level with Annotation in Hibernate

Uable to achieve aggressive/eager loading at Collection level.

I know eager loading at collection level with XML

enter image description here

but How I could achieve the same with annotation at collection level.?

Student Persistence Class

enter image description here

Here I need to do eager loading for Collection Type semails field.

Upvotes: 0

Views: 601

Answers (2)

Ilya Sereb
Ilya Sereb

Reputation: 2561

If you are using hibernate you can use @Fetch annotation with FetchMode.JOIN. This will make hibernate use join and fetch collection with a single select query joining your element collection table. Make sure your collection has two annotations:

@ElementCollection(fetch=FetchType.EAGER)
@Fetch(FetchMode.JOIN)

Upvotes: 1

Tiéris Valente
Tiéris Valente

Reputation: 11

You can set the fetch type in the annotation @ElementCollection:

@ElementCollection(fetch=FetchType.EAGER)

Upvotes: 1

Related Questions