facebook

Auto Generated Spring DAO findByExample problem!

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

    panickert
    Member

    Hello All,

    Consider following code using SpringDAO and Hibernate:-

    AssetLocationTrackingId alID = new AssetLocationTrackingId();
    AssetLocationTracking altRec = new AssetLocationTracking();
    altRec.setId(alID); //(Also tried with out this line…)
    Asset aRec = new Asset();

    AssetDAO adao = (AssetDAO) ctx.getBean(“AssetDAO”);
    AssetLocationTrackingDAO altdao = (AssetLocationTrackingDAO) ctx.getBean(“AssetLocationTrackingDAO”);

    List<AssetLocationTracking> lalt = altdao.findByExample(altRec);
    List<Asset> la = adao.findByExample(aRec);

    I have records for both Asset and AssetLocationTracking in the Db – However, only la <Asset> seems to return records. The size of lalt <AssetLocationTracking> always seems to be 0. The apparent difference between these two records are that AssetLocationTracking has compound primary key (AssetLocationTrackingId) and Asset does not. (another table with compound primary key works by the way.)

    My question is why this is so? Is there any other way to access all the records with out editing the autogenerated DAO’s (have too many DAO’s to edit and the structure of db is changing). Better yet, is there another velocity template that would do the trick?

    Thanks in advance for the help,

    #253733 Reply

    panickert
    Member

    Installation Summary!
    *** Date: Wed Jun 21 08:47:04 EDT 2006

    *** System properties:
    OS=WindowsXP
    OS version=5.1
    Java version=1.5.0_06

    *** MyEclipse details:
    MyEclipse Enterprise Workbench

    Version: 5.0 Milestone 1
    Build id: 20060515-5.0-M1

    *** Eclipse details:
    Eclipse SDK

    Version: 3.2.0
    Build id: I20060519-1206

    Eclipse Platform

    Version: 3.2.0.v20060518-_OZ2g5CC6lxEcKN
    Build id: I20060519-1206

    Eclipse Java Development Tools

    Version: 3.2.0.v20060518-0800-F7snp7fkt1-SXVP
    Build id: I20060519-1206

    Eclipse Project SDK

    Version: 3.2.0.v20060404-uDflzhCgQw7A-gJ
    Build id: I20060519-1206

    Eclipse Graphical Editing Framework

    Version: 3.1
    Build id: 20060504-1058

    Eclipse RCP

    Version: 3.2.0.v20060511-2000-VDNgUk84W-MjLLR
    Build id: I20060519-1206

    Eclipse Plug-in Development Environment

    Version: 3.2.0.v20060511-1200-6zXJJzJsQooFXED
    Build id: I20060519-1206

    Eclipse startup command=-os
    win32
    -ws
    win32
    -arch
    x86
    -launcher
    C:\eclipse\eclipse-SDK-3.2RC5-MyE5x\eclipse\eclipse.exe
    -name
    Eclipse
    -showsplash
    600
    -exitdata
    12d0_98
    -vm
    C:\WINDOWS\system32\javaw.exe

    #253734 Reply

    Haris Peco
    Member

    panickert,

    findByExample use simple hibernate Example queries (chapter 15.6 in hibernate documentation).You can set property show_sql to true in hibernate.cfg.xml and see what sql hibernate generate.

    Best regards

    #253735 Reply

    panickert
    Member

    Do you have a simple example for this? Sorry for being a pain.

    #253736 Reply

    panickert
    Member

    Thank you for such quick response by the way.

    #253737 Reply

    panickert
    Member

    Oh yea, how would you turn on property show_sql to true in hibernate.cfg.xml — if the config is embedded in spring applicationContext.xml?

    #253738 Reply

    Haris Peco
    Member

    just add property in hibernate.cfg.xml – you can use MyEclipse configuration editor or just add

    <property name=”hibernate.show_sql”>true</property>

    Best

    #253740 Reply

    panickert
    Member

    Okay so here it is – First statement where clause says 1=1 and the second one says ????. How come? Any thoughts?

    Hibernate: select this_.ASSET_ID as ASSET1_0_, this_.ASSET_CURRENT_ORGANIZATION_ID as ASSET2_40_0_, this_.ASSET_MANUFACTURER_ID as ASSET3_40_0_, this_.ASSET_STATUS_ID as ASSET4_40_0_, this_.ASSET_MODEL_ID as ASSET5_40_0_, this_.ASSET_HOME_ORGANIZATION_ID as ASSET6_40_0_, this_.ASSET_TYPE_ID as ASSET7_40_0_, this_.ASSET_NAME as ASSET8_40_0_, this_.ASSET_DESCRIPTION as ASSET9_40_0_, this_.ASSET_COMMENTS as ASSET10_40_0_, this_.ASSET_MAKE_CODE as ASSET11_40_0_, this_.ASSET_PLATFORM_CODE as ASSET12_40_0_, this_.ASSET_CLASS_CODE as ASSET13_40_0_, this_.ASSET_CG_CODE as ASSET14_40_0_, this_.ASSET_DIMENSION_CODE as ASSET15_40_0_, this_.ASSET_IMAGE_URL as ASSET16_40_0_, this_.ASSET_WEBSITE_URL as ASSET17_40_0_, this_.ASSET_GAMS_NAME as ASSET18_40_0_ from LEVER.ASSET this_ where (1=1)
    adao.findByExample(aRec) li.size()=268

    Hibernate: select this_.ASSET_ID as ASSET1_0_, this_.ASSET_LOCATION_TRACKING_ID as ASSET2_0_, this_.LOCATION_ID as LOCATION3_46_0_, this_.ASSET_ID as ASSET1_46_0_, this_.ASSET_LOCATION_TIME as ASSET4_46_0_, this_.ASSET_LOCATION_LATITUDE as ASSET5_46_0_, this_.ASSET_LOCATION_LONGITUDE as ASSET6_46_0_, this_.ASSET_LOCATION_ALTITUDE as ASSET7_46_0_, this_.ASSET_LOCATION_COURSE as ASSET8_46_0_, this_.ASSET_LOCATION_SPEED as ASSET9_46_0_ from LEVER.ASSET_LOCATION_TRACKING this_ where (this_.ASSET_LOCATION_LATITUDE=? and this_.ASSET_LOCATION_LONGITUDE=? and this_.ASSET_LOCATION_ALTITUDE=? and this_.ASSET_LOCATION_COURSE=? and this_.ASSET_LOCATION_SPEED=?)
    altdao.findByExample(altRec) lalt.size()=0

    #253743 Reply

    Haris Peco
    Member

    Example query work so that add where for all non-null properties – it mean (for example) that all primitive property will be in where clause
    This query mean that property (in query 2) are non-null.If this don’t help you then you will have to build query for your case
    However, in M2 (end of June) we add methods for search DAO for som eproperty (findByProperty) – I don’t sure if this will help you

    Best regards

    #253744 Reply

    panickert
    Member

    Thanks that did help…

    The solution was to generate the DAO’s and DO’s using java type mappings instead of hibernate type mappings (primitives).

    Thanks again for your excellent quick responses.

    #253745 Reply

    Haris Peco
    Member

    I’m glad for your success

    Thanks

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: Auto Generated Spring DAO findByExample problem!

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