Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Mapping specific property across table with filtering

 
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....
 
Master Rancher
Posts: 4664
49
  • 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
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic