I am trying out a web app using servlets and jsps and need to model isbn number of an item in my class as well as in hibernate mappings. Which should be the type of an isbn number?Long or String? I had come across many tutorials that use either of them.. isbn is supposedly a 10 digit identifier..sometimes you come across numbers like 0-85131-041-9 which cannot be a Long ..Some examples use numbers without hyphens..
So,which should be the type? Any suggestions?
thanks
mark
ISBN has 13 digits (see wiki). I would use a class that checks the validity of given String
. Something like:
class ISBN {
private String isbn;
public ISBN(String isbn) throws ISBNFormatException {
// you might want to filter hyphens first, before the check
if(ISBN.isValid(isbn)) this.isbn = isbn;
else throw new ISBNFormatException(isbn);
}
public static boolean isValid(String s) {
// validate number here, see wiki
}
}
This, of course, may be a bit too much. If your app is really simple, you may go with String
just fine.
Edit The hyphenation divides the number into groups (language, publisher, etc.). However, as for the uniqueness of the number, hyphenation (or division with spaces) plays no role.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With