-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Entity association is null
PostPosted: Tue Jun 19, 2012 6:57 am 
Newbie

Joined: Tue Jun 19, 2012 6:46 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.