Issue
I am using Spring Data JPA to create and query my tables.
This is my UserService
class,
@Service
public class UserService {
@Autowired
UserRepository userRepository;
public User saveUser(User u) {
User savedUser = userRepository.save(u); //<----- line that I debug
return savedUser;
}
public boolean usernameExists(String username) {
List<User> users = userRepository.findByUsername(username); //<----- line that I debug
return !users.isEmpty();
}
}
and this is the UserRepository
class
public interface UserRepository extends CrudRepository<User, Integer> {
public List<User> findByUsername(String username);
}
I am debugging my code and when the reach the above 'linesToDebug', I do a Step-Into in my IDE, hoping I would be taken to the implementation of the methods save()
and findByUsername()
, but nothing happens, the user is saved to the repository and my IDE (Netbeans 8.0) does not navigate to the implementation of these methods.
Which class has these methods implemented?
Edit: This is what I get in the console on the save() method:
2021-06-06 16:24:36.779 DEBUG 6948 --- [nio-8181-exec-5] org.hibernate.SQL : insert into user (date_created, password, username) values (?, ?, ?)
2021-06-06 16:24:36.784 TRACE 6948 --- [nio-8181-exec-5] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [TIMESTAMP] - [Sun Jun 06 16:24:27 IST 2021]
2021-06-06 16:24:36.791 TRACE 6948 --- [nio-8181-exec-5] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARCHAR] - [$2a$10$Ad0G05HssJUb4xaEMTqFTOlWZijMbXBSLSgyxbjVQzOEdZn7Lxuz2]
But there is no class named SQL
in org.hibernate
package .
Solution
Regarding your actual problem this question and its answers might help: How do I step into an implemented method in debug mode in NetBeans?
Regarding the question you asked in the title:
The CrudRepository
implementation in Spring Data JPA is SimpleJpaRepository
Regarding the question in the body of your post:
public List<User> findByUsername(String username);
is not part of an preexisting interface. So there is no direct implementation for it. Instead some dynamic code gets executed via proxies.
A good entry point to debug this is PartTreeJpaQuery.getExecution()
if you are interested in the construction of the query and AbstractJpaQuery.execute()
if you are more interested in the actual execution of the query.
Answered By - Jens Schauder
Answer Checked By - Candace Johnson (JavaFixing Volunteer)