Java hibernate映射在我的代码中不起作用

Java hibernate映射在我的代码中不起作用,java,spring,hibernate,Java,Spring,Hibernate,我有东西。个人资料、爱好、兴趣、用户 这些对象中的关系是用户配置文件1。 与爱好和兴趣有一对多关系的个人资料 代码如下所示:-- package com.dineshonjava.model; 导入javax.persistence.CascadeType; 导入javax.persistence.Column; 导入javax.persistence.Entity; 导入javax.persistence.FetchType; 导入javax.persistence.GeneratedValu

我有东西。个人资料、爱好、兴趣、用户

这些对象中的关系是用户配置文件1。 与爱好和兴趣有一对多关系的个人资料

代码如下所示:--

package com.dineshonjava.model;
导入javax.persistence.CascadeType;
导入javax.persistence.Column;
导入javax.persistence.Entity;
导入javax.persistence.FetchType;
导入javax.persistence.GeneratedValue;
导入javax.persistence.GenerationType;
导入javax.persistence.Id;
导入javax.persistence.JoinColumn;
导入javax.persistence.OneToOne;
导入javax.persistence.Table;
@实体
@表(name=“User”)
公共类用户{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
@列(name=“userId”)
私人国际ID;
@列(name=“name”)
私有字符串sName;
@列(name=“PASS”)
私人字符串sPass;
@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
@JoinColumn(name=“ProfileId”)
个人档案;
/**
*@返回个人资料
*/
公共配置文件getoSingleProfile(){
返回配置文件;
}
/**
*@param oSingleProfile要设置的oSingleProfile
*/
公共void setoSingleProfile(Profile oSingleProfile){
this.oSingleProfile=oSingleProfile;
}
公共用户(字符串sName、字符串SPAS){
超级();
this.sName=sName;
this.sPass=sPass;
}
公共用户(){
超级();
//TODO自动生成的构造函数存根
}
/**
*@还魂
*/
公共字符串getsName(){
返回sName;
}
/**
*@param sName要设置的sName
*/
公共名称(字符串sName){
this.sName=sName;
}
/**
*@返回sPass
*/
公共字符串getsPass(){
返回sPass;
}
/**
*@param sPass要设置的sPass
*/
公共通行证(字符串sPass){
this.sPass=sPass;
}
}
包com.dineshonjava.model;
导入java.util.ArrayList;
导入java.util.Collection;
导入java.util.List;
导入javax.persistence.CascadeType;
导入javax.persistence.Column;
导入javax.persistence.Entity;
导入javax.persistence.FetchType;
导入javax.persistence.GeneratedValue;
导入javax.persistence.GenerationType;
导入javax.persistence.Id;
导入javax.persistence.JoinColumn;
导入javax.persistence.MappedSuperclass;
导入javax.persistence.OneToMany;
导入javax.persistence.OneToOne;
导入javax.persistence.Table;
@实体
@表(name=“Profile”)
公共班级简介{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
@列(name=“Id”)
私人国际ID;
@列(name=“Address”)
私有字符串地址;
@列(name=“Zip”)
私人国际知识产权;
@独身癖
private Collection lstabby=new ArrayList();
@独身癖
private Collection lstInterest=new ArrayList();
公众简介(){
超级();
}
公共配置文件(字符串地址、整数iZip、集合地址、,
收款(利息){
超级();
地址=地址;
this.iZip=iZip;
this.lsthabby=lsthabby;
this.lstInterest=lstInterest;
}
公共字符串getAddress(){
回信地址;
}
公共无效设置地址(字符串地址){
地址=地址;
}
public int getiZip(){
返回iZip;
}
公共无效设置IP(内部设置IP){
this.iZip=iZip;
}
/**
*@把钱还给我
*/
公共集合getlsthabby(){
回归爱好;
}
/**
*@param lstHobby要设置的lstHobby
*/
公共空间setLstHobby(集合lstHobby){
this.lsthabby=lsthabby;
}
/**
*@归还利息
*/
公共集合getLstInterest(){
归还利息;
}
/**
*@param lstInterest要设置的lstInterest
*/
公共无效集合利息(集合利息){
this.lstInterest=lstInterest;
}
}
包com.dineshonjava.model;
导入javax.persistence.Column;
导入javax.persistence.Entity;
导入javax.persistence.GeneratedValue;
导入javax.persistence.GenerationType;
导入javax.persistence.Id;
导入javax.persistence.manytone;
导入javax.persistence.Table;
@实体
@表(name=“Hobby”)
公共课爱好{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
@列(name=“id”)
私人国际ID;
@列(name=“HobbyName”)
私有字符串sHobbyName;
公共爱好{
超级();
//TODO自动生成的构造函数存根
}
公共字符串getsHobbyName(){
返回sHobbyName;
}
公共爱好(字符串sHobbyName){
超级();
this.sHobbyName=sHobbyName;
}
/**
*@param sHobbyName要设置的sHobbyName
*/
public void setsHobbyName(字符串sHobbyName){
this.sHobbyName=sHobbyName;
}
}
我正在编写一个测试类来测试服务层

package com.dineshonjava.tester;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.dineshonjava.model.Hobby;
import com.dineshonjava.model.Interest;
import com.dineshonjava.model.Profile;
import com.dineshonjava.model.User;
import com.dineshonjava.service.UserService;



public class ServiceTest {  

    private static SessionFactory sessionFactory;

    public static void main(String[] args) {        
        ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
                new String[] {"config/sdnext-servlet.xml"});        
        UserService userservice=(UserService)appContext.getBean("UserServiceImpl"); 

        List<Hobby> lsthobby=new ArrayList<Hobby>();
        List<Interest> lstinterest=new ArrayList<Interest>();   



        Profile p=new Profile();
        p.setAddress("fdsf");
        p.setiZip(11121);


        Hobby h1=new Hobby();
        h1.setsHobbyName("hobby1");
        h1.setsHobbyName("hobby2");

        Hobby h2=new Hobby();
        h2.setsHobbyName("hobby3");
        h2.setsHobbyName("hobby4");

        Interest int1=new Interest();
        int1.setsInterestName("interest1");
        int1.setsInterestName("interest2");

        lsthobby.add(h1);
        lsthobby.add(h2);
        lstinterest.add(int1);




        p.getLstHobby().add(h2);
        p.getLstHobby().add(h1);
        p.getLstInterest().add(int1);

        p.getLstHobby().add(h1);
        p.getLstHobby().add(h2);


        User user2=new User();
        user2.setsName("Prabhat2");
        user2.setsPass("prabhat4");
        user2.setoSingleProfile(p);


        Boolean ck=userservice.addUser(user2);

}
}
package com.dineshonjava.tester;
导入java.util.ArrayList;
导入java.util.Date;
导入java.util.Iterator;
导入java.util.List;
导入org.hibernate.SessionFactory;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.context.ApplicationContext;
导入org.springframework.context.support.ClassPathXmlApplicationContext;
导入com.dineshonjava.model.Hobby;
导入com.dineshonjava.model.Interest;
导入com.dineshonjava.model.Profile;
导入com.dineshonjava.model.User;
导入com.dineshonjava.service.UserService;
公共类ServiceTest{
私有静态SessionFactory SessionFactory;
公共统计
package com.dineshonjava.tester;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.dineshonjava.model.Hobby;
import com.dineshonjava.model.Interest;
import com.dineshonjava.model.Profile;
import com.dineshonjava.model.User;
import com.dineshonjava.service.UserService;



public class ServiceTest {  

    private static SessionFactory sessionFactory;

    public static void main(String[] args) {        
        ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
                new String[] {"config/sdnext-servlet.xml"});        
        UserService userservice=(UserService)appContext.getBean("UserServiceImpl"); 

        List<Hobby> lsthobby=new ArrayList<Hobby>();
        List<Interest> lstinterest=new ArrayList<Interest>();   



        Profile p=new Profile();
        p.setAddress("fdsf");
        p.setiZip(11121);


        Hobby h1=new Hobby();
        h1.setsHobbyName("hobby1");
        h1.setsHobbyName("hobby2");

        Hobby h2=new Hobby();
        h2.setsHobbyName("hobby3");
        h2.setsHobbyName("hobby4");

        Interest int1=new Interest();
        int1.setsInterestName("interest1");
        int1.setsInterestName("interest2");

        lsthobby.add(h1);
        lsthobby.add(h2);
        lstinterest.add(int1);




        p.getLstHobby().add(h2);
        p.getLstHobby().add(h1);
        p.getLstInterest().add(int1);

        p.getLstHobby().add(h1);
        p.getLstHobby().add(h2);


        User user2=new User();
        user2.setsName("Prabhat2");
        user2.setsPass("prabhat4");
        user2.setoSingleProfile(p);


        Boolean ck=userservice.addUser(user2);

}
}
@OneToMany(cascade = CascadeType.ALL)