1

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

Grim
  • 1,938
  • 10
  • 56
  • 123

2 Answers2

0

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.

Markus
  • 3,297
  • 4
  • 31
  • 52
  • is java, sql-output is "select *** from ***" without where. – Grim Oct 24 '12 at 17:19
  • Ahh java, I confused them in my mind... `select *** from ***` I'm afraid I can't be of more help. (are there really triple stars, or is that just to show them on wiki?) – Markus Oct 25 '12 at 06:50
  • dont worry, nice try anyway. Those *** are just to show them on wiki ;D – Grim Oct 25 '12 at 07:34
  • @Markus it is obviously Java but not C# :) because methods' name are in camelCase but not PascalCase. – Adrian Shum Oct 25 '12 at 08:13
0

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.

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
  • i got a property named "char sex" what doesent has been printed to console. char cant be null – Grim Oct 25 '12 at 08:16