heatonn1 wrote:
Do you know what the necessary of hibernate initializing the proxy is?
I am really no hibernate expert at all. Just started using it in may :-)
But even if an association (be it a to-one or a collection) is loaded lazily (default) the actual entity holding the association (the Person in your case) has a proxy set in place of the actual associated entities. This proxy holds the primary key of the target table so if the property of that entity is accessed later on with an open hibernate session it can be loaded with an extra query from the database or throw a LazyInitializationException if the session is closed.
As already mentioned this is why I am guessing that hibernate makes a join on your PersonAddress table. Maybe one of the experts here can correct me if I am wrong or explain more detailed.
If you do not want to load the addresses at all you could use projections in combination with a result transformer to specify the properties of your Person class that should be fetched from the database.
Code:
Criteria query = getSession().createCriteria(Person.class);
// some criterion to determine the record(s)
query.add(Restrictions.like("name", p_searchInput));
// projection list for property selection
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.property("name"), "name");
projectionList.add(Projections.property("persno"), "persno");
// any property of Person.class you want to load
query.setProjection(projectionList);
// result transformer to get results as Person instances
query.setResultTransformer(Transformers.aliasToBean(Person.class));
return query.list();
Regards
Sebastian