Announcement Announcement Module
No announcement yet.
problem in posting data in one to one mapping Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem in posting data in one to one mapping

    i am experiencing problem when my form post data to save to database by jpa where i have used one to one mapping to a class. the there is exception occurs that says that

    org.springframework.beans.NullValueInNestedPathExc eption: Invalid property 'user' of bean class [org.mkcl.iforum.adnan.domain.UsersCredentials]: Value of nested property 'user' is null at org.springframework.beans.BeanWrapperImpl.getNeste dBeanWrapper( at org.springframework.beans.BeanWrapperImpl.getBeanW rapperForPropertyPath( at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue( at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues( 8) at org.springframework.validation.DataBinder.applyPro pertyValues( at org.springframework.validation.DataBinder.doBind(D at org.springframework.web.bind.WebDataBinder.doBind( at org.springframework.web.bind.ServletRequestDataBin der.bind( at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter$ArgumentsResolver.reso lveArguments( 98) at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho at org.springframework.web.servlet.DispatcherServlet. doDispatch( at org.springframework.web.servlet.DispatcherServlet. doService( at org.springframework.web.servlet.FrameworkServlet.p rocessRequest( at org.springframework.web.servlet.FrameworkServlet.d oPost( ..... ..... ....

    the details of my code is given below..

    I have class

    @Entity @Table(name="USERS") public class UsersCredentials {

    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private long id;

    @Column(length =30)
    private String username;

    @Column(length =30)
    private String password;

    @Column(length =30)
    private boolean enabled;

    @OneToOne(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "UserID")
    @Cascade(value = CascadeType.ALL)
    private User user;
    /// followed by getter setter


    and another class that is one property of above class making one to one mapping

    @Entity @Table(name="USER") public class User {

    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "USER_ID")
    private long userID;

    @Column(length =30)
    private String firstName;

    @Column(length =30)
    private String lastName;

    @Column(length =160)
    private String aboutMe;

    @Column(length = 100000)
    private byte[] photoInByte;
    //getter and setters }

    as you see the relation ship between two table is one to one. now the controller that handles get and post request

    @Controller @RequestMapping("/EmployeeRepository.htm*") public class EmployeeRepositoryController {

    IUser user;

    IUserCredentials userCredentials;

    @RequestMapping(method = RequestMethod.GET)
    public String showUserDetails(ModelMap model) {
    System.out.println("in get method");
    model.addAttribute("userMap",userCredentials.findB yUsername(SecurityContextHolder.getContext().getAu thentication().getName()));
    return "EmployeeRepository";

    public void setBinder(WebDataBinder binder, WebRequest requ8est){
    UserCustomEditor custom = new UserCustomEditor();
    binder.registerCustomEditor(User.class,"user", custom);


    @RequestMapping(method = RequestMethod.POST)
    public String UpdateEmployee(@ModelAttribute("userMap") UsersCredentials cred){
    System.out.println("before to be saved");
    User u = user.findByUserid(2);
    return "redirect:EmployeeRepository.htm";

    and the form that display that content in response to get and post request the EmployeeRepository.jsp

    User Id ${userMap.user.userID} First Name Enter/Update first name of the employee Last Name Enter/Update last name of the employee Username Enter/Update user of the employee Password Enter/Update password of the employee Location Enter/Update location of the employee Designation Enter Designation of the employee About Employee
    Not more than 160 chars.

    and one more class ie the custom binding editor class is

    public class UserCustomEditor extends PropertyEditorSupport {

    IUser user;
    private String format;

    public IUser getUser() {
    return user;

    public void setUser(IUser user) {
    this.user = user;

    public void setFormat(String format) {
    this.format = format;

    public void setAsText(String text){
    User user1 = user.findByUserid(Long.parseLong(text));

    now when i get data by user object of UserCredential there no problem in fetching data but once i post data after editing as u see the post handler of controller the exception thrown... help me as i am not able to solve it from 2 days...