Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping specific property across table with filtering

 
Steve Staarask
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Would appreciate any help as I have been trying to do this for a while.


Current Setup:






So in this setup, Class X is an entity mapping to Table X. And Class Y is an entity mapping to Table Y. column_x is a primary key for Table X, and column_x and column_y make up the primary keys for Table Y.
These entities are extracted from the database by a value of column_x, which loads 1 X, with a list of multiple Ys. This all has been simplified a bit only showing relevant columns.

Y is basically a deprecated table except for ONE value of column_z. Namely, the value of column_z when column_y is equal to a specific value. We don't want to load thousands of Class Ys anymore in Class X, it takes too much memory, we just want that ONE value of column_z. Here is how we want it to look:




And class Y no longer exists

Is this possible? We are

1) Getting only ONE row from Y when earlier we were getting all the rows
2) That one row is mapped with the constraint on column_Y
3) We are also throwing away the rest of Y completely






 
Steve Staarask
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be clear, there are 3 steps to this:


1) How will we load from the tables
2) How we will set up our annotations and mappings
3) How we will save this data back into the correct table and row


For 1, I am thinking we could set up an additional query to pull out the correct row and column and save it onto entity A. I think that should work. It will require 2 different queries (one to load A and the other to load that data for A), while previously we just had 1 query loading A and the rest was just automatically mapped by @OneToMany and loaded. So if someone knows a better way to do this let me know.

For 2, it will depend on what we decide to do for 1 and 3.

For 3, I am really not sure....
 
Dave Tolls
Ranch Hand
Posts: 2103
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I take it simply restructuring the table (X) is out of the question?
ALTER...ADD COLUMN z.
Then UPDATE X SET z = select from Y?
 
Steve Staarask
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:I take it simply restructuring the table (X) is out of the question?
ALTER...ADD COLUMN z.
Then UPDATE X SET z = select from Y?


Yes changing the actual schema of the table is not an option. Well it is an option but it will require A LOT of work because of all the legacy dependencies on the current table schema
But yes we basically want to model the schema change in hibernate without actually changing the schema
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic