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.

2
  • "I have thought about iterating over my list and manually setting it" Could you please explain this solution in more details? Commented Jun 16, 2015 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"); } Commented Jun 16, 2015 at 14:29

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.