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. 

SampleApplication.java

@SpringBootApplication
public class SampleApplication implements CommandLineRunner {

@Autowired
DataSource dataSource;

@Autowired
private UserRepository userRepository;

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


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

@Transactional(readOnly = true)
@Override
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"));
} }

UserRepository.java

@EnableJpaRepositories
@Repository
public interface UserRepository extends CrudRepository<User,Long> {

User findByName(String name);

}

User.java

@Entity
@Table(name="USER")
public class User
  implements Serializable
{
  private static final long serialVersionUID = 1L;
  @Id
  @SequenceGenerator(name="USER_ID_GENERATOR", sequenceName="USER_SEQ")
  @GeneratedValue(strategy=GenerationType.AUTO, generator="USER_ID_GENERATOR")
  private Long id;
  @Column(name="NAME")
  private String name;
  @Column(name="PASSWORD")
  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; }

UserLoginController.java

@Controller
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);

@Autowired
DataSource dataSource;

@Autowired
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.

logger.debug(userLoginController.getUserInfo("user","pword"));

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

pom.xml

<?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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>robicash</groupId>
    <artifactId>distributorcommision</artifactId>
    <version>1.0</version>
    <name>distributorcommission</name>
    <description>commision for distributors</description>

&lt;properties&gt;
    &lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;/properties&gt;

&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
        &lt;exclusions&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
                &lt;artifactId&gt;tomcat-jdbc&lt;/artifactId&gt;
            &lt;/exclusion&gt;
        &lt;/exclusions&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
        &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.mindrot&lt;/groupId&gt;
        &lt;artifactId&gt;jbcrypt&lt;/artifactId&gt;
        &lt;version&gt;0.3m&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;!--&lt;dependency&gt;--&gt;
        &lt;!--&lt;groupId&gt;com.oracle&lt;/groupId&gt;--&gt;
        &lt;!--&lt;artifactId&gt;ojdbc8&lt;/artifactId&gt;--&gt;
        &lt;!--&lt;version&gt;11.2.0.4&lt;/version&gt;--&gt;
    &lt;!--&lt;/dependency&gt;--&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.zaxxer&lt;/groupId&gt;
        &lt;artifactId&gt;HikariCP&lt;/artifactId&gt;
        &lt;version&gt;2.6.0&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.oracle&lt;/groupId&gt;
        &lt;artifactId&gt;ojdbc7&lt;/artifactId&gt;
        &lt;version&gt;12.1.0&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

</project>

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.