User类对应User表
public class User {
private long id;
private String name;
private String username;
private String password;
private String address;
private int mobile;
         //set get函数
        。
}
User.hbm.xml
<hibernate-mapping>
<class name="com.domain.User" table="user">
<id name="id" column="id" type="long">
<generator class="increment"></generator>
</id>

<property name="name" column="name" type="string"></property>
<property name="username" column="username" type="string"></property>
<property name="password" column="password" type="string"></property>
<property name="address" column="address" type="string"></property>
<property name="mobile" column="mobile" type="int"></property>

</class></hibernate-mapping>然后做了简单的用户保存public class HibernateTest {
private static SessionFactory sessionFactory;

static{
try{
sessionFactory = new Configuration().configure().buildSessionFactory();
}
catch(Exception ex){
ex.printStackTrace();
}
}

public static void main(String[] args){
Session session = sessionFactory.openSession();
Transaction tx = null;

try{
tx = session.beginTransaction();

User user = new User();
user.setUsername("zhangsan");
user.setPassword("123");
user.setMobile(1234567);
user.setAddress("hangzhou");

session.save(user);
tx.commit();
}
catch(Exception ex){
if(null != tx){
tx.rollback();
}
}
finally{
session.close();
}

}
}但是一直报错误
org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

解决方案 »

  1.   

    很久没有用过了 不过我觉得可能是少加了一个属性user.setname("");
      

  2.   

    有没有在hibernate-cfg.xml中配置你的User??
    如果有尝试用annotation的方法来配置一下,看是否成功
      

  3.   

    我感觉你错误信息没贴全,大概猜了一下就是你看看你实体类的属性名和setName名是否一致
      

  4.   

    <property name="name" column="name" type="string"></property>
    <property name="username" column="username" type="string"></property>
    <property name="password" column="password" type="string"></property>
    <property name="address" column="address" type="string"></property>
    <property name="mobile" column="mobile" type="int"></property>column要用大写,Type中用string首字母大写String,你这些都是错的.
      

  5.   

    让你参考一下我的吧?
    Mapping xml:
    <?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE hibernate-mapping PUBLIC 
            '-//Hibernate/Hibernate Mapping DTD 3.0//EN' 
            
    'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'> 
    <hibernate-mapping> 
        <class name="Model.User" table="USER_T"> 
            <id name="Id" column="USERID"> 
                <generator class="assigned"/> 
            </id> 
        <property name="username" column="USERNAME"></property> 
        <property name="password" column="PW"></property> 
        </class> 
    </hibernate-mapping>hibernate.cfg.xml:
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    <session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">
    oracle.jdbc.OracleDriver
    </property>
    <property name="connection.url">
    jdbc:oracle:thin:@localhost:1521:fdcdemo
    </property>
    <property name="connection.username">fdc</property>
    <property name="connection.password">fdc</property> <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property> <!-- SQL dialect -->
    <property name="dialect">
    org.hibernate.dialect.OracleDialect
    </property> <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property> <property name="format_sql">true</property> <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">false</property>
    <mapping resource="Model/User.hbm.xml" /></session-factory></hibernate-configuration>