-->
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: Redundant classes necessary, just for DB functions??
PostPosted: Thu Mar 25, 2010 8:30 am 
Newbie

Joined: Thu Mar 25, 2010 7:55 am
Posts: 8
Hi all!

I have a question, something I have a really hard time finding any docs/example cases for:

I am working with a non-changeable PostgreSQL DB, and creating a pretty straightforward (Swing) App to edit manipulate data in it.

What makes it less straightforward is that to read certain Entities I am supposed to use a Database Function (like a prepared statement) that return EXACTLY the same columns as if I would read directly from the table that function is accessing (I still need to use the function, because things get filtered through the function).

But obviously, when the app should write back some Entites altered by the user (front end) I need to write them to the original table they are coming from.

So when I define the Entity in java I can do this, I can read and write to the table "report_entity_archive":

@Entity
@Table(name="report_entity_archive")
public class ReportEntity extends BaseEntity
{...}

But because I need to read from a function, I also need this

@Entity
@Table(name="awv.get_report_companies('T')")
public class FilteredReportEntity extends ReportEntity
{ //EMPTY, I just need this to point to the Database function, but has the same fields like ReportEntity }

Reading from the function works fine, in a way, but of course I cant persist with this class, because you cant update/insert to a database function (sql syntax error).

Which I thought is fine, I thought I can just query the objects using the "FilteredReportEntity.class" and then downcast it to "ReportEntity" and store that with .save(..).

But Hibernate starts behaving really weirdly, as soon as I add "FilteredReportEntity" to the mapped classes Hibernate will query for them twice, even though I only call .list(..) once. It will select all from the table used for the ReportEntity, but then also query all from the db-function used in FilteredReportEntity and I have all in my list.

And also, if I want to persist the ReportEntity (by "downcasting" FilteredReportEntity to ReportEntity) it will still try to persist to the DB function rather than the table.

Does that mean I need two redundant classes with exactly the same fields, and manual field copying between them, just to be able to read from a db function, but write to a normal table (remember, both have exactly(!!) the same result fields).

I hope this made sense, any help/thoughts/critisism is appreciated!!

Cheers!!
CC!


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.