Hello everybody i am new to the hibernate. I have a method that is purposed to get a single column.
@Override public List<User> getUsersByEmail(String email) { session = sessionFact.openSession(); Query query = session.getNamedQuery("User.findByEmail"); query.setParameter("email", email); return query.list(); } After that, the returned value is used by the controller that further returns JSON data. It is supposed to return a user data but returns nothing.
@RequestMapping(value = "/api/customer/customer-id/{email}", method = RequestMethod.GET) public @ResponseBody List<User> getUserId(@PathVariable String email) { return customerDaoImp.getUsersByEmail(email); } Entity Class User.java
@Entity @Table(name = "tbl_user", catalog = "lifestyle", schema = "") @NamedQueries({ @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u") , @NamedQuery(name = "User.findByUserId", query = "SELECT u FROM User u WHERE u.userId = :userId") , @NamedQuery(name = "User.findByFullName", query = "SELECT u FROM User u WHERE u.fullName = :fullName") , @NamedQuery(name = "User.findByAddress", query = "SELECT u FROM User u WHERE u.address = :address") , @NamedQuery(name = "User.findByContact", query = "SELECT u FROM User u WHERE u.contact = :contact") , @NamedQuery(name = "User.findByGender", query = "SELECT u FROM User u WHERE u.gender = :gender") , @NamedQuery(name = "User.findByDob", query = "SELECT u FROM User u WHERE u.dob = :dob") , @NamedQuery(name = "User.findByEmail", query = "SELECT u FROM User u WHERE u.email = :email") , @NamedQuery(name = "User.findByPassword", query = "SELECT u FROM User u WHERE u.password = :password") , @NamedQuery(name = "User.findByActive", query = "SELECT u FROM User u WHERE u.active = :active") , @NamedQuery(name = "User.findByCreatedDate", query = "SELECT u FROM User u WHERE u.createdDate = :createdDate")}) public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "user_id") private Integer userId; @NotNull @Size(min = 1, max = 256) @Column(name = "full_name") private String fullName; @Size(max = 256) @Column(name = "address") private String address; @Size(max = 30) @Column(name = "contact") private String contact; @Size(max = 10) @Column(name = "gender") private String gender; @Column(name = "dob") @Temporal(TemporalType.DATE) private Date dob; // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation @NotNull @Size(min = 1, max = 256) @Column(name = "email") private String email; @NotNull @Size(min = 1, max = 256) @Column(name = "password") private String password; @NotNull @Column(name = "active", insertable = false) private short active; @Column(name = "created_date", insertable = false) @Temporal(TemporalType.TIMESTAMP) private Date createdDate; public User() { } public User(Integer userId) { this.userId = userId; } public User(Integer userId, String fullName, String email, String password, short active) { this.userId = userId; this.fullName = fullName; this.email = email; this.password = password; this.active = active; } //getter and setter http://localhost:8080/LifeStyle/api/customer/customer-id/[email protected]
This is the url i have entered to get a value