facebook

Hibernate returns incorrect results

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #261370 Reply

    ksgetting
    Participant

    I am running with Version: 5.0.1 GA
    Build id: 20060810-5.0.1-GA

    I am trying to implement Hibernate with the help of your tools and instructions. For one of the tables that I need to query. I used your Reverse engineering tool to generate all of the hibernate java/xml objects. The tool sets every field from the table as part of the key, which does not work for my situation (in reality, only 4 fields would be needed for a unique key). So I have tried to modify the xml and java parts to only have a few fields listed as part of the id. All that is background info.

    Here is the problem. When I run the query, the SQL generated in the log appears to be correct (I can manually run the SQL and get back the correct results). The SQL for the query looks like the following:

    Hibernate: select formatfiel0_.FLDMOD as FLDMOD2_, formatfiel0_.FLFMNM as FLFMNM2_, formatfiel0_.FLUSR as FLUSR2_, formatfiel0_.FLDTYP as FLDTYP2_, formatfiel0_.FLDFLN as FLDFLN2_, formatfiel0_.FLDNAM as FLDNAM2_, formatfiel0_.FLDDES as FLDDES2_, formatfiel0_.FLDROW as FLDROW2_, formatfiel0_.FLDCOL as FLDCOL2_, formatfiel0_.FLDLEN as FLDLEN2_, formatfiel0_.FLDDEC as FLDDEC2_, formatfiel0_.FLDVRY as FLDVRY2_, formatfiel0_.FLDFNT as FLDFNT2_, formatfiel0_.FLDSTL as FLDSTL2_, formatfiel0_.FLDCKD as FLDCKD2_, formatfiel0_.FLDFRT as FLDFRT2_, formatfiel0_.FLDALN as FLDALN2_, formatfiel0_.FLDIFL as FLDIFL2_, formatfiel0_.FLDIVL as FLDIVL2_, formatfiel0_.FLTECD as FLTECD2_, formatfiel0_.FLTHMG as FLTHMG2_, formatfiel0_.FLTWMG as FLTWMG2_, formatfiel0_.FLTHGT as FLTHGT2_, formatfiel0_.FLTWDT as FLTWDT2_, formatfiel0_.FLTPNT as FLTPNT2_, formatfiel0_.FLTCRT as FLTCRT2_, formatfiel0_.FLTCLR as FLTCLR2_, formatfiel0_.FLTGAP as FLTGAP2_, formatfiel0_.FLTBER as FLTBER2_, formatfiel0_.FLTBEC as FLTBEC2_, formatfiel0_.FLTBSP as FLTBSP2_, formatfiel0_.FLBDNS as FLBDNS2_, formatfiel0_.FLBHGT as FLBHGT2_, formatfiel0_.FLBHR as FLBHR2_, formatfiel0_.FLBNW as FLBNW2_, formatfiel0_.FLBWNR as FLBWNR2_, formatfiel0_.FLBSCL as FLBSCL2_, formatfiel0_.FLBNCL as FLBNCL2_, formatfiel0_.FLBMWD as FLBMWD2_, formatfiel0_.FLBBHT as FLBBHT2_, formatfiel0_.FLLTHC as FLLTHC2_, formatfiel0_.FLLPTN as FLLPTN2_, formatfiel0_.FLLROW as FLLROW2_, formatfiel0_.FLLCOL as FLLCOL2_, formatfiel0_.FLGGRA as FLGGRA2_, formatfiel0_.FLGLEN as FLGLEN2_, formatfiel0_.FLGWDT as FLGWDT2_, formatfiel0_.FLRTGB as FLRTGB2_, formatfiel0_.FLRENC as FLRENC2_, formatfiel0_.FLRAOF as FLRAOF2_, formatfiel0_.FLRNRT as FLRNRT2_, formatfiel0_.FLRVTG as FLRVTG2_, formatfiel0_.FLRVWT as FLRVWT2_, formatfiel0_.FLRPRO as FLRPRO2_, formatfiel0_.FLRCVN as FLRCVN2_, formatfiel0_.FLRRTG as FLRRTG2_, formatfiel0_.FLRSBN as FLRSBN2_, formatfiel0_.FLPRTP as FLPRTP2_, formatfiel0_.FLPRFL as FLPRFL2_, formatfiel0_.FLPRLB as FLPRLB2_, formatfiel0_.FLPRUP as FLPRUP2_, formatfiel0_.FLPRUL as FLPRUL2_, formatfiel0_.FLSQGP as FLSQGP2_, formatfiel0_.FLSQNM as FLSQNM2_, formatfiel0_.FLSQRF as FLSQRF2_, formatfiel0_.FLSPLN as FLSPLN2_, formatfiel0_.FLSPCL as FLSPCL2_, formatfiel0_.FLBFPN as FLBFPN2_, formatfiel0_.FLITYP as FLITYP2_, formatfiel0_.FLVSN as FLVSN2_, formatfiel0_.FLUDT as FLUDT2_ from mrkmagdta.fldspf60 formatfiel0_ where flfmnm=’HIBERWHAT’ and fldmod=’HPPCL5′ order by flfmnm, fldmod

    The query code looks like the following:

    Query queryObject = getSession().createQuery(queryString);
    return queryObject.list();

    queryString = “from FormatField where flfmnm = ‘HIBERWHAT’ and fldmod = ‘HPPCL5’ order by flfmnm, fldmod”. The list objected created contains 33 FieldFormat objects, as it should. However, each of the FieldFormat objects contain identical information (ie. they are all duplicate FieldFormat objects). As I said before, running the SQL query manually returns 33 rows that are each unique.

    Why is each FieldFormat object identical? I have tried altering the query string in a variety of ways, including the use of parameter markers. If I had the hibernate source, I could at least walk through the hibernate code and have some idea of why I am getting duplicate objects. Placing a breakpoint in the constructor for the FormatField object shows that it is only getting called 1 time (even though 33 FormatField objects are returned).

    #261385 Reply

    ksgetting
    Participant

    I figured it out. The ID was not uniquely defined for this table. I had to add 2 more key-property’s.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Hibernate returns incorrect results

You must be logged in to post in the forum log in