-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Two query return same object
PostPosted: Wed Mar 31, 2010 10:49 am 
Newbie

Joined: Mon Sep 21, 2009 2:51 am
Posts: 5
Hi,

I'm writing an application for displaying timetable. Data are stored in a tiers database. I access data via hibernate. I'm using spring and hibernateTemplate.

I'm trying to get data for two weeks. In database, events are stored with week numbers as a string (a string representing all week for a year, you must have a Y in order to get the event matching a week, for example, for an event matching the two first week of the year, you will have "YYNNNNNNNN....").

in database
---------
| Event |
---------
| - date startHour (9:00)
| - date endHour (11:00)
| - string weeks (YYNYNNNNNNNNNNNNNNNNN...NNNNNNNNNNNNNNNNNNNNNY)*
---------
| transient Calendar selectedWeek**
---------

* meaning first, second and fourth week of year and last week of year)
** week used to query the object, because I do query week by week


In the event class, I added a transient variable selectedWeek of type Calendar in order to store the week I used to query this object. I simplify my life after.

So I need to do two query to get events for the two next weeks. So my code is : select blabla where week like "Y%" and a second with : select blabla where week like "_Y%"

The problem I have is that the two query return the same event (and so the same hibernate object). The first query set the selectedWeek with first week of year, but the second set it with the second week of year.

What I want is that the two query return me the same event but in two different hibernate object (because the same event occurs in two differents weeks).

Is it possible ? Am I clear ?


Top
 Profile  
 
 Post subject: Re: Two query return same object
PostPosted: Wed Mar 31, 2010 11:00 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
What I want is that the two query return me the same event but in two different hibernate object


This is not possible within the same persistent context (session).
If you want to have 2 distinct objects for the same record on the database,
then you must issue the 2 query from 2 distinct sessions.
See http://docs.jboss.org/hibernate/core/4.0/manual/en-US/html/transactions.html#transactions-basics-identity


Last edited by pb00067 on Tue Feb 21, 2012 7:00 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Two query return same object
PostPosted: Wed Mar 31, 2010 11:52 am 
Newbie

Joined: Mon Sep 21, 2009 2:51 am
Posts: 5
hum. The problem is that I use the openSessionViewInFilter to get the same hibernate session along the user request (and to be able to access lazy data in my jsp).

Seems like I have to make my application a bit different...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.