程序问题:myeclipse开发hibernate
程序问题:myeclipse开发hibernate:错误:javax.servlet.ServletException:couldnotinsert:[com.mappi...
程序问题:myeclipse开发hibernate:
错误:
javax.servlet.ServletException: could not insert: [com.mapping.Userlist]
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
程序代码:
RegisterForm registerForm = (RegisterForm) form;
String userName=registerForm.getUserName();
String password=registerForm.getPassword();
Session session=SessionFactory.currentSession();
Transaction tx=session.beginTransaction();
Userlist ulist=new Userlist();
ulist.setName(userName);
ulist.setPassword(password);
session.save(ulist);
执行到倒数第二句都没有问题。
Userlist.hbm.xml:
<hibernate-mapping package="com.mapping">
<class name="Userlist" table="userlist">
<id name="name" column="name" type="java.lang.String">
<generator class="native"/>
</id>
<property name="password" column="password" type="java.lang.String" not-null="true" />
</class>
</hibernate-mapping>
后面有:
tx.commit();
SessionFactory.closeSession();
根本就没有openSession()的方法阿 展开
错误:
javax.servlet.ServletException: could not insert: [com.mapping.Userlist]
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
程序代码:
RegisterForm registerForm = (RegisterForm) form;
String userName=registerForm.getUserName();
String password=registerForm.getPassword();
Session session=SessionFactory.currentSession();
Transaction tx=session.beginTransaction();
Userlist ulist=new Userlist();
ulist.setName(userName);
ulist.setPassword(password);
session.save(ulist);
执行到倒数第二句都没有问题。
Userlist.hbm.xml:
<hibernate-mapping package="com.mapping">
<class name="Userlist" table="userlist">
<id name="name" column="name" type="java.lang.String">
<generator class="native"/>
</id>
<property name="password" column="password" type="java.lang.String" not-null="true" />
</class>
</hibernate-mapping>
后面有:
tx.commit();
SessionFactory.closeSession();
根本就没有openSession()的方法阿 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询