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)

Roohi
  • 7
  • How are they different? – M. Deinum Apr 18 '23 at 13:11
  • For postgres data is being stored as jsonb and for sql it’s json – Roohi Apr 18 '23 at 13:13
  • Shouldn't that be part of the actual dialect instead of your entities? Or you can have a look at https://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. – M. Deinum Apr 18 '23 at 13:21

0 Answers0