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

JIRA (TEMPO) - Date is closed to registration

jira jira-plugin

Can someone explain to me how to use this function?

Subtract a set percentage from a column?

sql postgresql case

I have a small query where code_price is 10% of list price. The problem is that sometimes the code price comes up the same as list price, so I tried this in my query.

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.