Hi all,
I have the user class, with a foreign key profiles:
public class Users implements java.io.Serializable {
private Integer idUser; private Profiles profiles; public Users() { }
public Users(Profiles profiles) { this.profiles = profiles; }
public Integer getIdUser() { return this.idUser; }
public void setIdUser(Integer idUser) { this.idUser = idUser; }
public Profiles getProfiles() { return this.profiles; }
public void setProfiles(Profiles profiles) { this.profiles = profiles; }
}
User.hbm.xml file:
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 19-may-2012 18:48:35 by Hibernate Tools 3.4.0.CR1 --> <hibernate-mapping> <class name="com.consulting.dto.Users" table="users" catalog="consulting"> <id name="idUser" type="java.lang.Integer"> <column name="idUser" /> <generator class="identity" /> </id> <many-to-one class="com.consulting.dto.Profiles" column="idProfile" name="profiles" not-null="true"/> </class> </hibernate-mapping>
I obtain the object with:
public Users validarUsuario(int id){ Session session = null; try{ session=this.getHibernateTemplate(); session.beginTransaction(); Criteria criterio=session.createCriteria(Users.class); criterio.add(Restrictions.eq("idUser", id)); List<Users> list= criterio.list(); if (list!=null && list.size()>0) return list.get(0); else return null; }catch (RuntimeException re) { log.error("find by example failed", re); throw re; }finally{ if(session != null){ try{ session.close(); } catch(HibernateException e}; } } }
The object user is loaded correctly, but the problem is when I try to access to user.profile.x, the profile always is null.
Any suggestion?
Thanks in advance.
|