how to ignore fetching a child table in hibernate

i have two tables . health & Network

This is my Health Table Entity:

   @Table(name="health")
   public class Health   implements Serializable {

private static final long serialVersionUID = 1L;

@Id 
@Column(name="hid")
private int hid;

@Column(name="ivid")
private int ivid;

@JoinColumn(name = "nwid")
@ManyToOne(fetch = FetchType.LAZY)
private Networks nwid;

}

I am trying to fetch a Health row against which there is nothing available in Network Table and thats why its not giving me that rows record of health table..

Where as i want that row from health and i dont want it to look into the network table for that record..

If i dont use crit.createAlias... server call get failed.

            try
      {
        session = sessionFactory.openSession();
        Criteria crit = session.createCriteria(Health.class);
        crit.createAlias("nwid", "network");
        crit.createAlias("network.statsId", "stats");
        crit.add(Restrictions.eq("ivid", 0));   
        Iterator<Health> it = crit.list().iterator();
        while(it.hasNext()){
        health  = it.next();

        }

Answers


Try to change this:

crit.createAlias("nwid", "network");

to

crit.createAlias("nwid", "network", CriteriaSpecification.LEFT_JOIN);

Need Your Help

Cross User-Base on multiple CMS installations

php content-management-system user-management

Will, I'm just going to open this again and again if you are going to close it. It is a very practical question asked ALL over the internet with mundane answers. If you don't understand what the we...

There actually is COBOL in .NET?

.net cobol microfocus

I was checking Microsoft's Visual Studio page just now and in the advertisements sidebar I suddenly saw an incredible advertisement:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.