Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 在spring中的两个映射表中插入数据_Hibernate_Spring_Spring Mvc_Hibernate Mapping - Fatal编程技术网

Hibernate 在spring中的两个映射表中插入数据

Hibernate 在spring中的两个映射表中插入数据,hibernate,spring,spring-mvc,hibernate-mapping,Hibernate,Spring,Spring Mvc,Hibernate Mapping,我有两个表user和userprofile相互映射 在User.java中,userprofile的getter方法是: @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user") public Userprofile getUserprofiles() { return this.userprofiles; } 在Userprofile.java中,用户的getter方法是:

我有两个表user和userprofile相互映射

在User.java中,userprofile的getter方法是:

 @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
 public Userprofile getUserprofiles() {
    return this.userprofiles;
 }
在Userprofile.java中,用户的getter方法是:

 @OneToOne(fetch = FetchType.LAZY)
 @JoinColumn(name = "UserID")
 public User getUser() {
    return this.user;
 }
在User.jsp中,commandName是“userprofile”,controller中的submit方法是:

 @RequestMapping("/insertUser.do")
 public ModelAndView showLoginForm( @ModelAttribute("userprofile") Userprofile userProfileBean,BindingResult result, HttpServletRequest request, HttpServletResponse response )throws Exception
{

            java.util.Date utilDate=new java.util.Date();
            java.sql.Timestamp timest=new Timestamp(utilDate.getTime());

            userProfileBean.setEntryDate(timest);

            User user = new User();
            user.setUserProfile(userProfileBean);
            this.userServ.createUser(user);
            return new ModelAndView(new RedirectView("usersMapping.do"), "Test", "Test");

}
当我调用user类的insert方法时,它将插入到user和userprofile表中,但在userprofile表中userid没有更新


请提供帮助。

您应该将用户配置文件添加到用户配置文件中

user.setUserProfile(userProfileBean);
还将用户对象添加到userProfileBean

userProfileBean.setUser(user);

谢谢,它现在正在工作,我缺少userProfileBean.setUser(user);