V
V
Venot2021-09-23 22:03:55
Java
Venot, 2021-09-23 22:03:55

How to ask Hibernate to save a value depending on the database?

https://stackoverflow.com/questions/27804069/hiber...

How to make hibernate work with enum as needed depending on the database, the method above works with postgres, but tests on H2 fail, I want a universal implementation.

st.setObject(index, value.toString(),Types.OTHER); here in this line, if the database is H2, then a prefix is ​​added to the value and everything breaks because of this, if TYPE string everything works, but it breaks with postgres.

Maybe somewhere you need a typedef or @Type annotation how to redefine it differently, in general, if some methods are not crutch?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BorLaze, 2021-09-23
@BorLaze

the above method works with postgres, but the tests for H2 fail, I want a universal implementation

do tests on embedded postgres

D
Dmitry Roo, 2021-09-24
@xez

Changing code for tests is a bad idea.
It’s not at all clear what you are checking there if your test database is different from the one that will be on the production.
Look at testcontainers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question