• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to exclude some indexed items in Hibernate List  RSS feed

 
Bala Gangadhar
Ranch Hand
Posts: 119
1
  • Mark post as helpful
  • send pies
  • 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 ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bala,
Can you elaborate on how you know which two you want excluded?
 
Bala Gangadhar
Ranch Hand
Posts: 119
1
  • Mark post as helpful
  • send pies
  • 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 Gangadhar
Ranch Hand
Posts: 119
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne, did you get a chance to look at this please..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!