0

I am building a springboot app which can connect to either sql or postgres db based on configuration. Entity for the two databases are slightly different. Is it possible to create 2 different entity for 2 databases and load them dynamically on startup based on db configuration. Or will I have to maintain 2 code bases. Let me know if more information is required.

I was thinking of creating two different entity classes with only columns that are different and they inherit from same base class. But I don’t know how to load dynamically based on db (property)

3
  • How are they different? Commented Apr 18, 2023 at 13:11
  • For postgres data is being stored as jsonb and for sql it’s json Commented Apr 18, 2023 at 13:13
  • Shouldn't that be part of the actual dialect instead of your entities? Or you can have a look at github.com/vladmihalcea/hypersistence-utils which supports JSON types for different databases. Else use profiles and provide an orm.xml which contains the mapping for the entities for the specific database and load the one you need based on the profile. Commented Apr 18, 2023 at 13:21

0

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.