I would like to run a criteria query on an entity using a join with another entity. But from Java/Hibernate point of view there is no reference to this second entity, there is only one from this second to the first entity.
To make it understandable, here is the cat'ifized situation:
===== Cat.java =====
@Id private long id;
@Column( unique = true, nullable = false )
private String name;
===== Kitten.java =====
@Id private long id;
@Column( unique = true, nullable = false )
private String name;
@OneToOne(optional = false)
private Cat mother; //only one child per mother ...
Now I want to query Cats with Restrictions and OrderBy for Kitten.
session.createCriteria(Cat.class)
.createAlias(???? , "kitten")
.add( Restrictions.like( "kitten.name", "name_of_a_kitten" )
.addOrder( Order.asc( "kitten.name" ) )
.list();
First I thought of using subqueries but I couldn't find a solution for ordering and subquerys aren't as readable as an alias in my eyes.
Cat can't be changed so there is no way to change probably to bi-directionallity.
How can I achive the query?
Btw. I'm using hibernate 4.2.