Question

I gota wired problem.

I use the Hibernate to find entities by Example.

Unfortunately I can not find any instance even if i got I have about 20000 entries in the Table.

My question is, how to debug this problem.

01  Puppy p = new Puppy()
02  List list = session.createCriteria(Puppy.class).add(Example.create(p)).list();
03  System.out.println(list.length());

Returns 0

EDIT: I even set all n-m and 1-n reations to null

Était-ce utile?

La solution

You are performing Query By Example, which means the properties in the Puppy instance p will generate the corresponding query, so that the result set matches with the example.

I suspect there are some non-null properties in your Puppy instance.

The easiest way to debug is to turn on SQL trace in Hibernate, so that you know what is the generated SQL, and hence, know what is the query criteria, and hence, know what field in the example instance is causing the problem.

Autres conseils

First of all, System.out.println looks like c#? So NHibernate?

In my project I have a configuration section and I can add a property there:

NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration();

configuration.SetProperty(NHibernate.Cfg.Environment.ShowSql, "true");

Hope that this helps in someway.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top