PO:User.javapackage cn.signup.po;import java.util.Date;/**
 * User entity.
 * 
 * @author MyEclipse Persistence Tools
 */public class User implements java.io.Serializable { // Fields private Integer userId;
private String username;
private String password;
private String email;
private String nickname;
private Integer sex;
private Integer point;
private Integer joinCount;
private Integer createCount;
private Date lastLoginTime;
private Integer state;

private UserExtend userExtend = new UserExtend(); // Constructors /** default constructor */
public User() {
} /** full constructor */
public User(String username, String password, String email,
String nickname, Integer sex, Integer point, Integer joinCount,
Integer createCount, Date lastLoginTime, Integer state) {
this.username = username;
this.password = password;
this.email = email;
this.nickname = nickname;
this.sex = sex;
this.point = point;
this.joinCount = joinCount;
this.createCount = createCount;
this.lastLoginTime = lastLoginTime;
this.state = state;
} // Property accessors public Integer getUserId() {
return this.userId;
} public void setUserId(Integer userId) {
this.userId = userId;
} public String getUsername() {
return this.username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return this.password;
} public void setPassword(String password) {
this.password = password;
} public String getEmail() {
return this.email;
} public void setEmail(String email) {
this.email = email;
} public String getNickname() {
return this.nickname;
} public void setNickname(String nickname) {
this.nickname = nickname;
} public Integer getSex() {
return sex;
} public void setSex(Integer sex) {
this.sex = sex;
} public Integer getPoint() {
return this.point;
} public void setPoint(Integer point) {
this.point = point;
} public Integer getJoinCount() {
return this.joinCount;
} public void setJoinCount(Integer joinCount) {
this.joinCount = joinCount;
} public Integer getCreateCount() {
return this.createCount;
} public void setCreateCount(Integer createCount) {
this.createCount = createCount;
} public Date getLastLoginTime() {
return this.lastLoginTime;
} public void setLastLoginTime(Date lastLoginTime) {
this.lastLoginTime = lastLoginTime;
} public Integer getState() {
return this.state;
} public void setState(Integer state) {
this.state = state;
} public UserExtend getUserExtend() {
return userExtend;
} public void setUserExtend(UserExtend userExtend) {
this.userExtend = userExtend;
}
}
UserExtend.javapackage cn.signup.po;/**
 * UserExtend entity.
 * 
 * @author MyEclipse Persistence Tools
 */public class UserExtend implements java.io.Serializable { // Fields private Integer userExtendId;
private Integer userId;
private String username;
private String nickname;
private String city;
private String address;
private String zipcode;
private String truename;
private Integer birthYear;
private Integer birthMonth;
private Integer birthDay;
private String findpasswordQuestion;
private String findpasswordAnswer;
private String qq;
private String msn;
private String intro;
private String sign;

private User user = new User(); // Constructors /** default constructor */
public UserExtend() {
} /** minimal constructor */
public UserExtend(Integer userId, String username, String nickname) {
this.userId = userId;
this.username = username;
this.nickname = nickname;
} /** full constructor */
public UserExtend(Integer userId, String username, String nickname,
String city, String address, String zipcode, String truename,
Integer birthYear, Integer birthMonth, Integer birthDay,
String findpasswordQuestion, String findpasswordAnswer, String qq,
String msn, String intro, String sign) {
this.userId = userId;
this.username = username;
this.nickname = nickname;
this.city = city;
this.address = address;
this.zipcode = zipcode;
this.truename = truename;
this.birthYear = birthYear;
this.birthMonth = birthMonth;
this.birthDay = birthDay;
this.findpasswordQuestion = findpasswordQuestion;
this.findpasswordAnswer = findpasswordAnswer;
this.qq = qq;
this.msn = msn;
this.intro = intro;
this.sign = sign;
} // Property accessors public Integer getUserExtendId() {
return this.userExtendId;
} public void setUserExtendId(Integer userExtendId) {
this.userExtendId = userExtendId;
} public Integer getUserId() {
return this.userId;
} public void setUserId(Integer userId) {
this.userId = userId;
} public String getUsername() {
return this.username;
} public void setUsername(String username) {
this.username = username;
} public String getNickname() {
return this.nickname;
} public void setNickname(String nickname) {
this.nickname = nickname;
} public String getCity() {
return this.city;
} public void setCity(String city) {
this.city = city;
} public String getAddress() {
return this.address;
} public void setAddress(String address) {
this.address = address;
} public String getZipcode() {
return this.zipcode;
} public void setZipcode(String zipcode) {
this.zipcode = zipcode;
} public String getTruename() {
return this.truename;
} public void setTruename(String truename) {
this.truename = truename;
} public Integer getBirthYear() {
return this.birthYear;
} public void setBirthYear(Integer birthYear) {
this.birthYear = birthYear;
} public Integer getBirthMonth() {
return this.birthMonth;
} public void setBirthMonth(Integer birthMonth) {
this.birthMonth = birthMonth;
} public Integer getBirthDay() {
return this.birthDay;
} public void setBirthDay(Integer birthDay) {
this.birthDay = birthDay;
} public String getFindpasswordQuestion() {
return this.findpasswordQuestion;
} public void setFindpasswordQuestion(String findpasswordQuestion) {
this.findpasswordQuestion = findpasswordQuestion;
} public String getFindpasswordAnswer() {
return this.findpasswordAnswer;
} public void setFindpasswordAnswer(String findpasswordAnswer) {
this.findpasswordAnswer = findpasswordAnswer;
} public String getQq() {
return this.qq;
} public void setQq(String qq) {
this.qq = qq;
} public String getMsn() {
return this.msn;
} public void setMsn(String msn) {
this.msn = msn;
} public String getIntro() {
return this.intro;
} public void setIntro(String intro) {
this.intro = intro;
} public String getSign() {
return this.sign;
} public void setSign(String sign) {
this.sign = sign;
} public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
}
}

解决方案 »

  1.   

    hbm.xml配置user.hbm.xml
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
        <class name="cn.signup.po.User" table="user" catalog="signup">
            <id name="userId" type="java.lang.Integer">
                <column name="user_id" />
                <generator class="native" />
            </id>
            <property name="username" type="java.lang.String">
                <column name="username" length="20" not-null="true" />
            </property>
            <property name="password" type="java.lang.String">
                <column name="password" length="200" not-null="true" />
            </property>
            <property name="email" type="java.lang.String">
                <column name="email" length="100" not-null="true" />
            </property>
            <property name="nickname" type="java.lang.String">
                <column name="nickname" length="30" not-null="true" />
            </property>
            <property name="sex" type="java.lang.Integer">
                <column name="sex" not-null="true" />
            </property>
            <property name="point" type="java.lang.Integer">
                <column name="point" not-null="true" />
            </property>
            <property name="joinCount" type="java.lang.Integer">
                <column name="join_count" not-null="true" />
            </property>
            <property name="createCount" type="java.lang.Integer">
                <column name="create_count" not-null="true" />
            </property>
            <property name="lastLoginTime" type="java.util.Date">
                <column name="last_login_time" length="19"/>
            </property>
            <property name="state" type="java.lang.Integer">
                <column name="state" not-null="true" />
            </property>
            
            
            <many-to-one name="userExtend" cascade="save-update" insert="false" update="false" unique="true" column="user_id" class="cn.signup.po.UserExtend"></many-to-one>
        
        </class>
    </hibernate-mapping>userExtend.hbm.xml<?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
        <class name="cn.signup.po.UserExtend" table="user_extend" catalog="signup">
            <id name="userExtendId" type="java.lang.Integer">
                <column name="user_extend_id" />
                <generator class="native" />
            </id>
            <property name="userId" type="java.lang.Integer" insert="false" update="false">
                <column name="user_id" not-null="true" />
            </property>
            <property name="username" type="java.lang.String">
                <column name="username" length="20" not-null="true" />
            </property>
            <property name="nickname" type="java.lang.String">
                <column name="nickname" length="30" not-null="true" />
            </property>
            <property name="city" type="java.lang.String">
                <column name="city" length="20" />
            </property>
            <property name="address" type="java.lang.String">
                <column name="address" length="200" />
            </property>
            <property name="zipcode" type="java.lang.String">
                <column name="zipcode" length="10" />
            </property>
            <property name="truename" type="java.lang.String">
                <column name="truename" length="20" />
            </property>
            <property name="birthYear" type="java.lang.Integer">
                <column name="birth_year" />
            </property>
            <property name="birthMonth" type="java.lang.Integer">
                <column name="birth_month" />
            </property>
            <property name="birthDay" type="java.lang.Integer">
                <column name="birth_day" />
            </property>
            <property name="findpasswordQuestion" type="java.lang.String">
                <column name="findpassword_question" length="30" />
            </property>
            <property name="findpasswordAnswer" type="java.lang.String">
                <column name="findpassword_answer" length="30" />
            </property>
            <property name="qq" type="java.lang.String">
                <column name="qq" length="20" />
            </property>
            <property name="msn" type="java.lang.String">
                <column name="msn" length="200" />
            </property>
            <property name="intro" type="java.lang.String">
                <column name="intro" length="100" />
            </property>
            <property name="sign" type="java.lang.String">
                <column name="sign" length="100" />
            </property>
          
          <many-to-one name="user" class="cn.signup.po.User" unique="true" foreign-key="user_id" column="user_id"></many-to-one>
        </class>
    </hibernate-mapping>
      

  2.   


    测试代码:
    User user = new User();
    user.setCreateCount(0);
    user.setJoinCount(0);
    user.setLastLoginTime(new Date());
    user.setPoint(0);
    user.setState(1);


    user.setUsername("limaoyuan");
    user.setNickname("maomao");
    user.setPassword("123456");
    user.setEmail("[email protected]");
    user.setSex(1);


    UserExtend ue = new UserExtend();
    ue.setAddress("西城");
    ue.setBirthDay(21);
    ue.setBirthMonth(9);
    ue.setBirthYear(1983);
    ue.setCity("beijing");
    ue.setFindpasswordAnswer("今天星期几");
    ue.setFindpasswordQuestion("星期八");
    ue.setIntro("无介绍");
    ue.setMsn("[email protected]");
    ue.setNickname(user.getNickname());
    ue.setQq("155331464");
    ue.setSign("无个性签名");
    ue.setTruename("茂茂");

    ue.setUserId(user.getUserId());
    ue.setUsername(user.getUsername());

    //ue.setUser(user);
    user.setUserExtend(ue);

    userManager.save(user);
    报错:
    严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/classes/application-dao.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/classes/application-dao.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/application-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectcn.signup.po.User
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:404)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:375)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:263)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:170)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:260)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:184)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:430)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:254)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:198)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/classes/application-dao.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/application-
      

  3.   

    后续的报错在这里:http://topic.csdn.net/u/20090212/14/cdd31561-ee0d-46d2-b816-ba9096ec6d3b.html
      

  4.   

    你的错误不在hibernate 的配置.
       Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/classes/application-dao.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/classes/application-dao.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/application-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectcn.signup.po.User 看这个错误.是你的spring的配置文件出错了...创建bean的时候出错.dataSourc bean. inner bean
    还有你的申明式事物'org.springframework.transaction.config.internalTransactionAdvisor'
    好好检查下
      

  5.   

    两个一对多双向?那不是[一对多(或多对一)双向关联
    ]不能这么写吧!
    user表要包含user_extends类,放在set里集合里.[一对多]Set<UserExtend> userExtend = new HashSet<UserExtend>(0);UserExtend 表包含User类,User user;