ssh简单集成实现简单添加,往Group添加Person后,该group的name属性变为null!!!这是怎么回事???Group与Person是一对多双向关联。
本来Group有两条记录id=1,name=陌生人;id=2,name=朋友。当通过页面添加成功一个Person后,Person里的groupid正常(比如说等于1),但查看Group表时,id=1的name=NULL
Group.hbm.xml:
<class name="sjzc.xhy.model.Group" table="t_group">
<id name="id">
<generator class="native"/>
</id>
<property name="name" />
<set name="persons" inverse="true">
<key column="groupid"/>
<one-to-many class="sjzc.xhy.model.Person" ></one-to-many>
</set>
</class>Person.hbm.xml:
<class name="sjzc.xhy.model.Person" table="t_person">
<id name="id">
<generator class="native"/>
</id>
<property name="name" />
<property name="address" />
<property name="qq" />
<many-to-one name="group" column="groupid" cascade="all"/>
</class>PS:另外还有出现了一个问题:通过页面添加到Person后,(1)该Person记录的name由于编码问题显示“???”,(2)离奇的是address设置为“beijing”后却显示Null,其他属性正常。
(1)jsp界面为gbk,mysql的clien也为gbk,为什么就显示“???”呢,费解!
(2)这种情况更是没有见过,感觉相当离奇。
添加界面的代码:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>(以前设置的都是UTF-8,显示也为“???”,所以才改成了gbk,但还是显示不出中文)
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'addPerson.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<form action="addPerson!addPerson.action">
姓名:<input name="name"></input><br/>
地址:<input name="adress"></input><br/>
qq: <input name="qq"></input><br/>
组:
<select name="group.id">
<s:iterator value="#groups">
<option value="<s:property value="id"/>">
<s:property value="name" />
</option>
</s:iterator>
</select><br/>
<input type="submit" value="添加">
</form>
</body>
</html>sshhibernate乱码
本来Group有两条记录id=1,name=陌生人;id=2,name=朋友。当通过页面添加成功一个Person后,Person里的groupid正常(比如说等于1),但查看Group表时,id=1的name=NULL
Group.hbm.xml:
<class name="sjzc.xhy.model.Group" table="t_group">
<id name="id">
<generator class="native"/>
</id>
<property name="name" />
<set name="persons" inverse="true">
<key column="groupid"/>
<one-to-many class="sjzc.xhy.model.Person" ></one-to-many>
</set>
</class>Person.hbm.xml:
<class name="sjzc.xhy.model.Person" table="t_person">
<id name="id">
<generator class="native"/>
</id>
<property name="name" />
<property name="address" />
<property name="qq" />
<many-to-one name="group" column="groupid" cascade="all"/>
</class>PS:另外还有出现了一个问题:通过页面添加到Person后,(1)该Person记录的name由于编码问题显示“???”,(2)离奇的是address设置为“beijing”后却显示Null,其他属性正常。
(1)jsp界面为gbk,mysql的clien也为gbk,为什么就显示“???”呢,费解!
(2)这种情况更是没有见过,感觉相当离奇。
添加界面的代码:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>(以前设置的都是UTF-8,显示也为“???”,所以才改成了gbk,但还是显示不出中文)
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'addPerson.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<form action="addPerson!addPerson.action">
姓名:<input name="name"></input><br/>
地址:<input name="adress"></input><br/>
qq: <input name="qq"></input><br/>
组:
<select name="group.id">
<s:iterator value="#groups">
<option value="<s:property value="id"/>">
<s:property value="name" />
</option>
</s:iterator>
</select><br/>
<input type="submit" value="添加">
</form>
</body>
</html>sshhibernate乱码
解决方案 »
- java -->> xml,,look!
- 求助!JSP为了防止重复添加记录违反PRIMARY KEY 约束
- 谁给我一份javamail的例子!
- 各位牛人帮忙解答一下“关于用JDBC连接Oracle数据库的问题”
- Caused by: org.hibernate.MappingException: Association references unmapped class: com.elone.pm.product.dao.TAttribute
- 关于首页的设置一问
- 请教一个jsp中文得问题
- 数据库与文件.
- 请高手解答
- 为何不使用window.location.href 而都使用ajax呢
- 请问如何将root目录中的404页面跳转?
- 请问lucene在使用 庖丁解牛 分次器的时候 为什么要设置PAODING_DIC_HOME 环境变量?
address更新不了是因为不小心把jsp中的“address”写错了。只是最开始提的group中name被取代为NULL不是知道是什么原因,还请各位牛人指点...
1.保存user
User u = new User();
u.setName("u");
Group g = new Group();
g.setName("g");
u.setGroup(g);
session.save(u);
2.保存group
User u1 = new User();
u1.setName("u1");
User u2 = new User();
u2.setName("u2");
Group g = new Group();
g.setName("g1");
g.getUsers().add(u1);
g.getUsers().add(u2);
u1.setGroup(g);
u2.setGroup(g);
sesion.save(g);