1

This is related to my other question here. I'm simply looking for a way (an annotation, system configuration etc) to make Hibernate skip over, or ignore columns in models, which do not align with the current ResultSet. To add clarification- I'm not referring to Transient properties, as these properties are all persisted, just each is not involved in every query.

Here is a quick summary of the situation:

  1. I do not have control over the tables, or the queries, everything is done with stored procedures (business decision, not mine).

  2. Because each stored procedure can vary vastly between one another, my idea is to consolidate "branching models" (models that only differ from each other by 1-2 columns) into several larger models, which I can then use to insert or retrieve data, while doing the mapping using DTOs.

  3. The only hang-up in this at the moment, is that Hibernate will throw a SQLException during hydration of a model entity, if it cannot find a matching column in the current ResultSet (funny enough, it doesn't seem to care about the other way around- i.e. if there's little to no columns in the entity, as long as one matches to the current ResultSet).

Any help would be much appreciated, as I've been trying to figure this out for a while now, and I'm about to go back to making each stored procedure have its own entity.

grantley
  • 127
  • 1
  • 12
  • design question .. are the stored procedures you want to consolidate relevant or it might end up with abstracting the whole database stored procedures in one business model? – osama yaccoub Aug 08 '21 at 04:03
  • @osamayaccoub The stored procedures are relevant, and the models themselves are mostly identical, with the differences between models mostly being a join on another table appearing as an additional column. – grantley Aug 09 '21 at 17:38

1 Answers1

1

That's not really possible and I would also not recommend this as that could hide mapping errors. If you can't convince the database team to add at least synthetic columns with constant values such that you can reuse the same mapping, you are unfortunately out of luck and will have to continue with your multiple mappings.

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
  • Thank you for the answer Christian. I was thinking this was likely the case, but I thought perhaps I was missing an otherwise obvious solution somewhere. Cheers! – grantley Aug 09 '21 at 17:36