hibernate的问题,请指点一二!
我的程序:
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
请问原因?