我用hibernate在一个表取出记录
Query query = session.createQuery("select User from hbExp.User User");
Collction col= query.list();
Iterator i=col.iterator();
然后println出每个列的值~结果userId列全部是0(如果不用hibernate而直接用JDBC是正常的),而其他列正常,大家觉得是什么原因?下面给出一些相关代码:
(1)**************************数据库:(MySQL)
create table ysf (
   userId int not null  AUTO_INCREMENT,
   username varchar(45),
   password varchar(45),
   role varchar(45),
   primary key (userId)
);
(2)**************************User.hbm.xml:
<hibernate-mapping>
    <class name="hbExp.User" table="ysf" >
        <id name="userId" column="userId" type="int" >
            <generator class="native"/>
        </id>
        <property name="username" column="username" type="string" /> 
        <property name="password" column="password" type="string" /> 
        <property name="role" column="role" type="string" /> 
     </class>
</hibernate-mapping>
(3)**************************User.class
package hbExp;import java.io.Serializable;public class User implements Serializable
{
private int userId;
private String username;
private String password;
private String role;

public int getUserId()
{
return this.userId;
}
public void setUserId(int uesrId)
{
this.userId=userId;
}

public String getUsername()
{
return this.username;
}
public void setUsername(String username)
{
this.username=username;
}

public String getPassword()
{
return this.password;
}
public void setPassword(String password)
{
this.password=password;
}

public String getRole()
{
return this.role;
}
public void setRole(String role)
{
this.role=role;
}

}