hibernate的问题,请指点一二!

zeq258 2005-03-25 01:29:40
我的程序:
POJO
PersonMedel.java
-------------------------------------------------------------
package hibernate01;
import java.io.Serializable;

public class PersonModel implements Serializable {
private String name;
private String password;

public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setPassword(String pasasword) {
this.password=password;
}
public String getPassword() {
return password;
}
}



PersonModel.hbm.xml
-----------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="hibernate01.PersonModel"
table="yonghu"
>
<id
name="name"
type="java.lang.String"
column="name"
>
<generator class="assigned" />
</id>
<property
name="password"
type="java.lang.String"
column="password"
length="255"
/>
<!-- Associations -->
</class>
</hibernate-mapping>

只有两个属性!


对数据库的操作 Client.java
---------------------------------------------------------------
package hibernate01;


import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
import net.sf.hibernate.cache.HashtableCacheProvider;
public class Client
{
private static SessionFactory sessionFactory;
public static String asc(String str){
try{
byte b[] = str.getBytes("ISO-8859-1");
str = new String(b);
return str;
}
catch(Exception e){ return null;}
}
public static void main(String[] args) throws Exception
{
Configuration conf = new Configuration().addClass(PersonModel.class);
sessionFactory = conf.buildSessionFactory();
Session s = sessionFactory.openSession();
Transaction t = s.beginTransaction();

PersonModel yuj = new PersonModel();
yuj.setName(asc("11"));
yuj.setPassword("11");
PersonModel yuj1 = new PersonModel();
yuj1.setName("22");
yuj1.setPassword("22");

//持久化
s.save(yuj); //此时yuj已经可以在数据库中找到
s.save(yuj1);
//s.flush();
t.commit();
s.close();
}
}


我的问题,在对数据库的插入操作,为什么只插入了name字段,password字段为 null

请问原因?
...全文
117 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jFresH_MaN 2005-03-28
  • 打赏
  • 举报
回复
帮你顶一下
这个代码好像没有什么问题啊
zeq258 2005-03-25
  • 打赏
  • 举报
回复
问题不在那里,java.lang.String
和String 基本是一样的。
就是一个需要引入包,一个不需要而已!
  • 打赏
  • 举报
回复
type="java.lang.String"?
应该type="string"试试看

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧