• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to exclude some indexed items in Hibernate List

 
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have the below settings in Hibernate where a Results has a list of Events.

<class name="com.example.Game" table="GAME" entity-name="Game">

<id name="eventId" column="EVENT_ID"></id>
<property name="gameId" column="GAME_ID" />
<property name="prize" column="PRIZE" />
<property name="info" column="INFO" />

<list name="results" table="EVENT" lazy="false">
<key column="EVENT_ID"></key>
<index column="ORDER_ID"></index>
<element type="short" column="DRAWN"></element>
</list>

</class>

And my Generic Query to load the games are

StringBuilder queryStr = new StringBuilder( "from Game g  where g.gameId = :gameId ");

But for a specific use case I need certain events should not be loaded.. for example, For a given game there are 6 events and i want to exclude 5 and 6 events to be loaded.

How can i specify in the HQL query ? Do I need to go to Native query and Build the Game Objects manually by iterating the results set ?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bala,
Can you elaborate on how you know which two you want excluded?
 
Bala Tilak
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for Reply Boyarsky.

I have configured in a properties file (kind of hard coded) for each game, for this use case. Which looks similar to...

312.excludes=5,6
313.excludes=1
314.excludes=2,3

Please note that i have different configuration file for different use cases...  For time being i am achieving the required query as below

if (excludes != null) {
queryStr.append(" and order_id not in (" + excludes + ")");
}
Query query = session.createSQLQuery((queryStr.toString()));

And iterating thorough results set and creating the Game object.
 
Bala Tilak
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeanne, did you get a chance to look at this please..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic