spring boot repository throws an exception

spring boot repository throws an exception

I am new to spring boot. 

I am new to spring boot. 

I have created my web application as below. 


public class SampleApplication implements CommandLineRunner {

DataSource dataSource;

private UserRepository userRepository;

Logger logger = LoggerFactory.getLogger(SampleApplication.class);

public static void main(String[] args) {
    SpringApplication.run(SampleApplication.class, args);

@Transactional(readOnly = true)
public void run(String... args) throws Exception {          
    UserLoginController userLoginController = new UserLoginController();

System.out.println("DATASOURCE = " + dataSource); logger.debug("\nUser: "+userRepository.findByName("user").getName()); logger.debug(userLoginController.getUserInfo("user","pword"));
} }


public interface UserRepository extends CrudRepository<User,Long> {

User findByName(String name);



public class User
  implements Serializable
  private static final long serialVersionUID = 1L;
  @SequenceGenerator(name="USER_ID_GENERATOR", sequenceName="USER_SEQ")
  @GeneratedValue(strategy=GenerationType.AUTO, generator="USER_ID_GENERATOR")
  private Long id;
  private String name;
  private Long password;
public Long getId()
    return this.id;

public void setId(Long id) { this.id = id; } public String getName() { return this.name; }

public void setName(String name) { this.name = name; }

public String getPassword() { return this.password; }

public void setPassword(String password) { this.password = password; }


public class UserLoginController {
    Logger logger = LoggerFactory.getLogger(UserLoginController.class);

@RequestMapping(value = "/userLogin**", method = RequestMethod.POST)
public @ResponseBody String getUserInfo(@RequestParam("mobile") String uName, @RequestParam("pin") String pWord){            
    logger.debug("UserLoginController | uName: " + uName + " pWord: " + pWord);

    UserLoginService userLoginService = new UserLoginService();

    String user = null;

    try {
        logger.debug("UserLoginController | Validate user. uName: " + uName + " pWord: " + pWord);
        user = userLoginService.validateSysUser(uName, pWord);
    } catch (Exception e) {
        logger.debug("UserLoginController | Validate user Exception: " + e.getMessage()+", "+e.getStackTrace());

    if (user != null) {
        logger.debug("UserLoginController | Returning aircash user");
        return user;
    } else {
        logger.debug("UserLoginController | Returning NULL");
        return null;



UserLoginService .java

public class UserLoginService {
    Logger logger = LoggerFactory.getLogger(UserLoginService.class);

DataSource dataSource;

private UserRepository userRepository;

public String validateSysUser(String uName, String pWord) throws Exception{
    logger.debug("UserLoginService | uName: "+uName+" pWord: "+pWord);       

    User user = new User();

    String auser = userRepository.findByName(uName).getName();

    if ((auser != null) &amp;&amp; (validatePword(user.getPassword(),pWord)){
        logger.debug("UserLoginService | User found: "+user.getName());
        return auser;
    }else {
        logger.debug("UserLoginService | User not found");
        return null;

public static boolean validatePword(String pWord,String pWord2){
    return BCrypt.checkpw(pWord2,pWord);


Problem is, When I run the application,This part give me the intended response

logger.debug("\nUser: "+userRepository.findByName("user").getContactNo());

But, next line throws an exception. I also tried calling the controller using the postman too. But the same exception comes.


The exception is thrown from the UserLoginService.java class. The exception message is shown as null


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <relativePath/> <!-- lookup parent from repository -->
    <description>commision for distributors</description>





I don't understand why the same repository give two results when called.

Can you please tell me how to get it working.

java hibernate spring jpa

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Multitenant configuration: StaleObjectStateException on Transaction (hibernate + spring-data-jpa)

i'm trying to setup a configuration for manage a multi-tenant enviroment with spring-boot, spring-data-jpa, hibernate and mysql (same schema, every tenant table has a tenant_code column). For dependencies the parent maven project is&nbsp;<strong>spring-boot-starter-parent</strong>&nbsp;(2.1.2.RELEASE).

Understand to Spring Boot: MySQL and JPA, Hibernate

Spring Boot uses Hibernate as the default JPA implementation. The property spring.jpa.hibernate.ddl-auto is used for database initialization. I've used the value “update” for this property.

Spring Boot + JPA + Hibernate + Oracle

In this tutorial, we will learn how to create a Spring Boot application that communicates with an Oracle data source through Hibernate.

Duplicate Entry Exception: Spring Hibernate/JPA cascade save Many To One

It is a spring application (no spring boot). The database I am using is MySQL. The issue I am having is when saving the entity&nbsp;<code>Driver</code>&nbsp;which has a Many to one relationship on both&nbsp;<code>Carrier</code>&nbsp;and&nbsp;<code>Location</code>.

How to Create Spring App using Hibernate/JPA with JNDI Data Source

Spring Persistence (Hibernate and JPA) with a JNDI datasource, we'll create a Spring application using Hibernate/JPA with a JNDI data source.