'No qualifying bean of type java.lang.String exception for normal field

I am getting the below error while running the application.Can any one please help me in understanding what I am doing wrong,

Error creating bean with name 'user' defined in file [C:\Users\Admin1\Login.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MVC\WEB-INF\classes\Validation\user.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.String' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

package Validation;
import java.util.Date;
import org.springframework.stereotype.Repository;

import DAO.Processor;

import javax.validation.constraints.Past;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@Repository
@Entity
@Table(name = "APP_USER", schema = "claim")
public class user {

 @Id
 private int uid;

 @OneToOne
 @JoinColumn(name = "PID")
 Processor P;

 @NotNull
 String username = null;
 @NotNull
 String password;
 public Processor getP() {
  return P;
 }

 public void setP(Processor p) {
  P = p;
 }

 @NotNull
 String email;
 @Past @NotNull
 Date DOB;

 public user(String username, String password, String email, Date dob) {

  this.email = email;
  this.username = username;
  this.DOB = dob;
  this.password = password;

 }

 public String getUsername() {
  return username;
 }

 public void setUsername(String username) {
  this.username = username;
 }

 public String getPassword() {
  return password;
 }

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

 public String getEmail() {
  return email;
 }

 public void setEmail(String email) {
  this.email = email;
 }

 public Date getDOB() {
  return DOB;
 }

 public void setDOB(Date dOB) {
  DOB = dOB;
 }
}


Solution 1:[1]

I was able to solve the problem by adding default constructor

public user(){}

hibernate requires default constructor for entity class.

Solution 2:[2]

You shouldn't add @Repository for the entity class. It will makes this class a component which will trigger the autowire for the parameters in your only constructor.

You should have another class as the repository for this table. Try following the instructions here: https://spring.io/guides/gs/accessing-data-jpa/

Solution 3:[3]

Adding @NoArgsConstructor worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tomerikoo
Solution 2 Tianhao Wang
Solution 3 Rajat Pratap