I'm trying to
@Id
@Column(name = "MY_ID_FIELD")
@Convert(converter = IdConverter.class)
private Long id;
IdConverter is:
@Converter
public class IdConverter implements AttributeConverter<Long, BigDecimal> {
@Override
public BigDecimal convertToDatabaseColumn(Long attribute) {
return BigDecimal.valueOf(attribute);
}
@Override
public Long convertToEntityAttribute(BigDecimal dbData) {
return dbData.longValue();
}
}
The converter will map BigDecimal, the attribute field type Hibernate expects given that in the sql server database the id column type is numeric, to Long.
I'm using Spring Data Jpa and my repository is using Long as I would expect to
@Repository
public interface CityRepository extends JpaRepository<City, Long> { }
Do you have any idea of why it is not working?
@Convert
not being applied to@Id
fields. I know that DataNucleus JPA allows it, but have also heard of others that don't.NUMERIC
is a floating-type number, I don't think there is much you could do (other than maybe changing the DB to useBIGINT
instead). If you're creating the database from scratch, then you are most likely trying to use the wrongorg.hibernate.dialect.Dialect
for your DB