首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

hibernate有关问题,们,给解决

2012-01-19 
hibernate问题,大虾们,给解决啊?xmlversion 1.0 encoding utf-8 ?!DOCTYPEhibernate-mappingPUBL

hibernate问题,大虾们,给解决啊
<?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   -   Hibernate   Tools
-->
<hibernate-mapping>
        <class   name= "com.test.hibernate.bean.Contact "   table= "contact "   catalog= "test ">
                <id   name= "id "   type= "short ">
                        <column   name= "id "   />
                        <generator   class= "native "   />
                </id>
                <many-to-one   name= "person "   class= "com.test.hibernate.bean.Person "   fetch= "select ">
                        <column   name= "cid "   not-null= "true "   />
                </many-to-one>
                <property   name= "mobilePhone "   type= "string ">
                        <column   name= "mobilePhone "   length= "20 "   />
                </property>
                <property   name= "fixedPhone "   type= "string ">
                        <column   name= "fixedPhone "   length= "20 "   />
                </property>
        </class>
</hibernate-mapping>
///////////////////////////////////////////////////////////////////////
<?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   -   Hibernate   Tools
-->
<hibernate-mapping>
        <class   name= "com.test.hibernate.bean.Person "   table= "person "   catalog= "test ">
                <id   name= "id "   type= "integer ">
                        <column   name= "id "   />
                        <generator   class= "native "   />
                </id>


                <property   name= "name "   type= "string ">
                        <column   name= "name "   length= "20 "   not-null= "true "   />
                </property>
                <property   name= "sex "   type= "string ">
                        <column   name= "sex "   length= "1 "   />
                </property>
                <property   name= "address "   type= "string ">
                        <column   name= "address "   length= "200 "   />
                </property>
                <property   name= "contact "   type= "integer ">
                        <column   name= "contact "   />
                </property>
                <set   name= "contacts "   inverse= "true ">
                        <key>
                                <column   name= "cid "   not-null= "true "   />
                        </key>
                        <one-to-many   class= "com.test.hibernate.bean.Contact "   />
                </set>
        </class>
</hibernate-mapping>
//////////////////////////////////////////////////////////////////////
/*
  *   Generated   by   MyEclipse   Struts
  *   Template   path:   templates/java/JavaClass.vtl
  */
package   com.test.struts.action;

import   javax.servlet.http.HttpServletRequest;
import   javax.servlet.http.HttpServletResponse;

import   org.apache.struts.action.Action;
import   org.apache.struts.action.ActionForm;
import   org.apache.struts.action.ActionForward;
import   org.apache.struts.action.ActionMapping;
import   org.hibernate.Session;
import   org.hibernate.Transaction;

import   com.test.hibernate.bean.Contact;
import   com.test.hibernate.bean.Person;
import   com.test.hibernate.factory.HibernateSessionFactory;
import   com.test.struts.form.PersonForm;

/**  
  *   MyEclipse   Struts
  *   Creation   date:   04-04-2007
  *  
  *   XDoclet   definition:
  *   @struts.action   path= "/com.test.struts.form.Person "   name= "com.test.struts.form.PersonForm "   input= "/index.jsp "   scope= "request "   validate= "true "


  */
public   class   PersonAction   extends   Action   {
/*
  *   Generated   Methods
  */

/**  
  *   Method   execute
  *   @param   mapping
  *   @param   form
  *   @param   request
  *   @param   response
  *   @return   ActionForward
  */
public   ActionForward   execute   (   ActionMapping   mapping     ,       ActionForm   form     ,       HttpServletRequest   request     ,       HttpServletResponse   response     )     {  
//PersonForm   PersonForm   =   (PersonForm)   form;//   TODO   Auto-generated   method   stub
Session   session   =   HibernateSessionFactory.getSession();
Transaction   tx   =   session.beginTransaction();
Person   person   =   new   Person();
Contact   contact   =   new   Contact();
person.setAddress( "www.1245.com ");
person.setName( "ganyichen ");
person.setSex( "F ");
contact.setFixedPhone( "123123123 ");
contact.setMobilePhone( "456456456 ");
//contact.setPerson(person);
//person.setContact(Integer.valueOf(contact.getId()));
person.getContacts().add(contact);
session.save(person);
tx.commit();
return   mapping.findForward( "ok ");
}
}


////////////////////////////////////////////////////////////////////
只能写进person表里的数据,contact写不进去啊

[解决办法]
up
[解决办法]
也刚开始学这个,帮你顶了
[解决办法]
把错误信息发出来啊

[解决办法]
你要把主要的问题写出来。
不要把代码一贴过来就完事儿

[解决办法]
<generator class= "native " /> 的问题,你在action里面用的assign方法,配置文件却用native,会出错的吧,你再研究下。

热点排行