I donβt know what the problem is with your hibernation configuration, but as a workaround, one trick that lets you not worry about what type of java Number Hibernate request returns is to cast the returned value to Number and call .longValue() :
long id = ((Number) em.createNativeQuery("select my_seq.nextVal from dual") .getSingleResult()) .longValue();
That way, you don't care if the query returns Long , BigDecimal , BigInteger , Short if it fits into Java long .
source share