In our entity beans we use a custom ID format which includes a checksum to verify that the ID is actually valid. Ids look like ID827391738979
. To make sure that
You could use a custom type in your entity with JPA 2.1 @Convert, so JPA makes the conversion for you (I've tested it with Spring Data JPA also, and it worked transparently!), see:
Entity:
@Entity
class SomeEntity {
@Column(name = "my_id_column_name")
@Convert(converter = MyIDConverter.class)
private ID itsID;
}
Converter:
public class MyIDConverter implements AttributeConverter<ID, String> {
@Override
public String convertToDatabaseColumn(ItStaticDataKey javaKey) {
// your implementation here
}
@Override
public ItStaticDataKey convertToEntityAttribute(final String databaseKey) {
// your implementation here
}
}
Notes:
packageToScan
on EntityManagerFactoryBean
.