BigInteger mapped to SqlTypes.NUMERIC instead of SqlTypes.BIGINT

In hibernate-orm/hibernate-core/src/main/java/org/hibernate/type/StandardBasicTypes.java at main · hibernate/hibernate-orm · GitHub , we have:

public static final BasicTypeReference<BigInteger> BIG_INTEGER = new BasicTypeReference<>(
		"big_integer",
		BigInteger.class,
		SqlTypes.NUMERIC
);

Why is SqlTypes.NUMERIC is used instead of SqlTypes.BIGINT for BigInteger ?

Note / consequence:

The executed query is equivalent to this SQL:

update my_table set my_field=‘x’ where my_bigint_id=2049145::numeric;

instead of:

update my_table set my_field=‘x’ where my_bigint_id=2049145;

On my PostgreSQL database, the index on the ‘my_bigint_id’ field is not used due to the numeric conversion. Therefore, the mapping to SqlTypes.NUMERIC is really bad for performance in this situation.

Thank you !

For one, the Jakarta Persistence specification defines this, but also because BIGINT always mapped to Long in JDBC drivers: Basic Features

Thank you for your reply.

I find it quite counterintuitive that, for a BIGINT column in PostgreSQL, java.lang.BigInteger is not the appropriate type to use, especially when working with indexed columns. It took me a while to understand why my DB index wasn’t being used. Even my profiler, VisualVM, didn’t reveal the cast to numeric in the SQL queries.

My knowledge in this area isn’t deep enough to know whether something could be done, at the level of Hibernate, PostgreSQL, VisualVM, or the JDBC driver, to at least warn developers when this happens. Just a thought. In any case, thank you again for your answer.