Anand Kadhi
Anand Kadhi

Reputation: 1888

Fetch ManytoOne based on certain condition

I am using Hibernate 3.5.4 version as Orm I have two tables which have many to one relationship , Like Table 'Book' can have many 'Authors' associated with It.

@OneToMany(mappedBy = "key.bookId", fetch = FetchType.EAGER, cascade = CascadeType.ALL)   
public Set<BookAuthor> getAuthors() {
    return authors;
}

But we use soft delete for deleting the association (we maintain a column named isDeleted) , i want to fetch the entity based on isDeleted check if its 1 it should not be loaded , else if 0 load it.

Is it possible by modifying this current fetching strategy to provide above support or there is another better solution that can be applied please let me know.

Upvotes: 1

Views: 374

Answers (1)

samjaf
samjaf

Reputation: 1053

Have a look at the @Filter or @Where Annotation.

As far as I know this is the usual way to restrict collection fetching.

Upvotes: 1

Related Questions