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.  [ 1 post ] 
Author Message
 Post subject: Issue with Entity using the @Where clause
PostPosted: Fri Sep 21, 2007 3:56 am 
Newbie

Joined: Fri Sep 21, 2007 3:32 am
Posts: 6
Hello
I'm backing my legacy system using hibernate.
The issue is related to a table with data records that are versionned.

Ie:
Code:
table VALUES_HISTORY
--------------------------------------------------------------------------
| Functional_Key | Valid_from | valid_to   | data_one | ...
--------------------------------------------------------------------------
| FKONE          | 2007-01-01 | 2007-07-12 | XXXXX    | ...
| FKONE          | 2007-07-13 | 2099-12-31 | XXXXX    | ...
| FKTWO          | ...


I map the bean LastValue to the table VALUES_HISTORY, and specify a @where clause to get only the last valid value.

Code:
@Entity
@Table(name = "VALUES_HISTORY")
@Where(clause = "valid_to = '2099-12-31')
public class LastValue {
   @Id
   @Column(name = "Functional_Key")
   private String functionalKey;
***
}


When I retrieve the bean through a finder, the @where clause is taken into account, aka the generated select includes valid_to = '2099-12-31'

The issue is when I use the entity as a FK object

ie
Code:
@Entity
@Table(name = "TABLE_WITH_VALUE")
public class ModelWithFk {
***

   @ManyToOne
   @JoinColumn(name = "Last_Value")
   private LastValue lastValue ;

***
}


When I retrieve a ModelWithFk using a Dao, I can see that the generated SQL does not contain the @Where clause specified for the LastValue bean. Hibernate then throws an exception if there is more than one record in VALUES_HISTORY for the specified value.

Could you tell me if this is an hibernate bug or if I made a mistake in the way I map beans.

Thanks in advance !!!


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

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.