For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 10 replies, 2 voices, and was last updated 19 years, 10 months ago by
Haris Peco.
-
AuthorPosts
-
panickertMemberHello 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,
June 21, 2006 at 7:47 am #253733
panickertMemberInstallation 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 WorkbenchVersion: 5.0 Milestone 1
Build id: 20060515-5.0-M1*** Eclipse details:
Eclipse SDKVersion: 3.2.0
Build id: I20060519-1206Eclipse Platform
Version: 3.2.0.v20060518-_OZ2g5CC6lxEcKN
Build id: I20060519-1206Eclipse Java Development Tools
Version: 3.2.0.v20060518-0800-F7snp7fkt1-SXVP
Build id: I20060519-1206Eclipse Project SDK
Version: 3.2.0.v20060404-uDflzhCgQw7A-gJ
Build id: I20060519-1206Eclipse Graphical Editing Framework
Version: 3.1
Build id: 20060504-1058Eclipse RCP
Version: 3.2.0.v20060511-2000-VDNgUk84W-MjLLR
Build id: I20060519-1206Eclipse Plug-in Development Environment
Version: 3.2.0.v20060511-1200-6zXJJzJsQooFXED
Build id: I20060519-1206Eclipse 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.exeJune 21, 2006 at 8:07 am #253734
Haris PecoMemberpanickert,
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
June 21, 2006 at 8:13 am #253735
panickertMemberDo you have a simple example for this? Sorry for being a pain.
June 21, 2006 at 8:22 am #253736
panickertMemberThank you for such quick response by the way.
June 21, 2006 at 8:23 am #253737
panickertMemberOh yea, how would you turn on property show_sql to true in hibernate.cfg.xml — if the config is embedded in spring applicationContext.xml?
June 21, 2006 at 8:25 am #253738
Haris PecoMemberjust add property in hibernate.cfg.xml – you can use MyEclipse configuration editor or just add
<property name=”hibernate.show_sql”>true</property>
Best
June 21, 2006 at 9:01 am #253740
panickertMemberOkay 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()=268Hibernate: 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()=0June 21, 2006 at 9:16 am #253743
Haris PecoMemberExample 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 youBest regards
June 21, 2006 at 9:50 am #253744
panickertMemberThanks 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.
June 21, 2006 at 10:01 am #253745
Haris PecoMemberI’m glad for your success
Thanks
-
AuthorPosts
