How to use StringDistance class in JPA
The class is StringDistance
not part of the JPA spec , but a utility class from apache OpenJPA
The class StringDistance
is useful for calculating Levenshtein distance
source to share
The Levenshtein distance between two lines is the minimum number of changes that must be applied to the first line in order to move to the second line. You can see here for the details of the algorithm.
The class StringDistance
has nothing to do with the JPA specification. It's just a utility class used by OpenJPA, which is one of the variants of the JPA specification. Apache Common also offers this feature
If OpenJPA encounters an invalid config property while parsing the openJPA config file, it will use the Levenshtein distance algorithm, calling getClosestLevenshteinDistance()
to find out the closest string of a valid property to that invalid property, so that it can provide a suggestion to fix that invalid property.
source to share