I'm new with Spring boot and JpaRepository. I was wondering why the use of Long instead of another data type?
CodePudding user response:
There is no need to use Long
, you can use any type like String
, UUID
or a custom type.
E.g. all these are possible:
public interface UserRepository extends CrudRepository<User, Long>
public interface UserRepository extends CrudRepository<User, String>
public interface UserRepository extends CrudRepository<User, UUID>
public interface UserRepository extends CrudRepository<User, UserId>
The important bit is that it refers to whatever you use as primary key for your entity.