How to select records based on foreign key in Hibernate ?

hinernate_logo

Take a Scenario,  We have two Entities: Login and AppDetails. Of these Entities  AppDetails has a foreign key  login  references the loginId column on Login Entity. So how could we query the AppDetails with a certain loginId ?
public class AppDetails{

private Login login; // foreign key
----
}

 
public class Login
{
private Integer loginId; // primary key
----
}

Here is the query :
session.createCriteria(AppDetails.class) .add(Restrictions.eq("login.loginId", loginId ));
Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment