-->
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: Same entities from multiple views
PostPosted: Mon Dec 13, 2010 4:32 pm 
Newbie

Joined: Mon Dec 13, 2010 4:11 pm
Posts: 1
Hello.
I have a database schema with one central transactions table and multiple views of that table. For simplicity, let's call the transactions table "TRANSACTIONS" and the views would be simple filters like "SUCCESSFUL_TRANSACTIONS" and "TRANSACTIONS_THAT_FAILED_WITH_ERROR_30" or something. All of these views have the same columns as the main TRANSACTIONS table; they're really just (complex) filters.
The application I am writing/redesigning takes user-inputted control files to choose which view it needs to use. The views somewhat independent of this program and their logic is best defined and kept on the database side. Further, the application doesn't necessarily know what or how many views there are, it just gets the name of the view.

Back in the bad old days when I composed by own SQL (last week), I could use a concept like this:
Code:
select * from ${users_view} where blah=blahblah
where users_view would get popped in. Then I'd go about the arduous task of manually mapping the fields out.

Now that I have Hibernate in my life, everything is great, mapping is easy, and the winter rainbows are shining. However, I'm not sure how to switch between views now.

I have an annotated entity, let's say it looks like this:
Code:
@Entity @Table(name="TRANSACTIONS")
public class TransactionEntry implements Serializable {
    /* Properties for ID, timestamps, return codes, etc
    */
}

Is there some what I can programmatically override the Table name..?

After some Googling on this issue, I saw an interesting suggestion to use @MappedSuperclass for the main TransactionEntry and subclasses for the different views. However, as views are added from time to time as needed, it would result in additional maintenance to create a new subclass for each one. Obviously, I'd like to avoid this.

I've also been thinking about hijacking Criteria output to feed it back into native SQL with the appropriate view inserted, but this is philosophically undesirable and negates most of the benefits of Hibernate.

In short, I want to share the same TransactionEntry Entity class between multiple views.

Am I overlooking anything obvious? Is there some way to explicitly specify which view I want to select from when slurping up Entities?

Hopefully I've explained my issue adequately.


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.