Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Hibernate unidirectional association

$
0
0
Lets say i have 2 classes Person and Address and i have a unidirectional association between them - ie. Person has an Address. My question is, will i be able to get a List of Person objects based on Address or do i need bidirection.

Query along the lines:

public static void getPeopleByAddress(String streetName){
        AnnotationConfiguration config = new AnnotationConfiguration();
        config.addAnnotatedClass(Person.class);
        config.addAnnotatedClass(Address.class);
        config.configure();
        Session session = config.buildSessionFactory().getCurrentSession();
        session.beginTransaction();
        Criteria criteria = session.createCriteria(Person.class);
        //get all people that live on the street name specified in the parameter
        criteria.add(Restrictions.????);
        List<Person> list = criteria.list();        
        session.getTransaction().commit();
    }


Viewing all articles
Browse latest Browse all 51036

Trending Articles