0

I have a use case where i am mapping two tables to the same object.

In this object i have a string called source and I want to be able to set the table name or the database name to this variable.

Any ideas on how to achieve this?

I have thought about iterating over my list and manually setting it but this has the potential to waste a fair chunk of time.

I appreciate this is somewhat of an odd request so this may be the only way but am hoping for a solution that maps the source variable when hibernate is mapping everything else.

user1383163
  • 577
  • 1
  • 7
  • 24
  • _"I have thought about iterating over my list and manually setting it"_ Could you please explain this solution in more details? – Dragan Bozanovic Jun 16 '15 at 14:08
  • so at the implementation of my dao (that has a seperate datasource than my other dao) i get my list of object via criteria.list() and then for(myObject current : myList){ current.setSource("tableOne"); } – user1383163 Jun 16 '15 at 14:29

3 Answers3

1

if i had understood correctly your issue , then your solution might be the MappedSuperClass , in which you must have an abstract class , which will have the common fields of the two tables and then you will extend that to the two entities you want , which will point to two different tables. Check this link

AntJavaDev
  • 1,204
  • 1
  • 18
  • 24
0

You could try to achieve this with Load listener or Interceptors. In the listener/interceptor you can check what the data source is and populate the source field accordingly.

Community
  • 1
  • 1
Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110
0

In the end i ended up using a formula to map my variable to a select statement which was sufficient for what i needed.

user1383163
  • 577
  • 1
  • 7
  • 24