johnson wang
johnson wang

Reputation: 35

What does this hibernate criteria example do?

I saw the following criteria example on hibernate tutorial web site, but I didn't know what it does, can somebody help explain?

List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "F%") )
.createCriteria("kittens")
    .add( Restrictions.like("name", "F%") )
.list();

Upvotes: 0

Views: 41

Answers (1)

JB Nizet
JB Nizet

Reputation: 691775

It returns all the cats whose name starts with F and who have at least one child whose name starts with F.

It's equivalent to the following HQL:

select cat from Cat cat
join cat.kittens child
where cat.name like 'F%' and child like 'F%'

Upvotes: 1

Related Questions