System.currentTimeMillis().toString();

解决方案 »

  1.   

    系统日期总不能当成主键来使吧……
    我想得到的是象:
    categoryID:1
    categoryID:2
    categoryID:3
    categoryID:4
    categoryID:5
    ....
    ....
    这样的结果……
      

  2.   

    我听人说hibernate里好象有生成自增长字段的方法,但我找了一下午了,就是没找到……才来求救的……
      

  3.   

    有点眉目了:
        <class name="Category" table="category">
            <id name="categoryid" column="categoryID" type="java.lang.Integer">
                <generator class="uuid.hex"/> <----这里写成这样就应该可以自动生成了吧?
            </id>但我获取的categoryid依然是null...不知是为什么...
    这是添加类别的方法
        public void addCategory(Category category) throws HibernateException{
            Session sess = SessionFactory.currentSession();
            Transaction tx = null;
            try{
                tx = sess.beginTransaction();
                System.out.println(category.getCategoryid()); //这里打印出来为null……
                System.out.println(category.getCategoryname());//这里正常
                sess.save(category);
                tx.commit();
            }catch(HibernateException hex){
                if(tx!=null){
                    tx.rollback();
                }
              //这里会捕获一个hibernate异常,因为categoryid是非空的键值
            }catch(Exception ex){
                if(tx!=null){
                    tx.rollback();
                }
            }finally{
                try{
                    SessionFactory.closeSession();
                }catch(HibernateException hex){
                }
            }//end finally block
        }//end addCategory() method不解中,望大家赐教。
      

  4.   

    <class name="Category" table="category">
            <id name="categoryid" column="categoryID" type="java.lang.Integer">
                <generator class="uuid.hex"/> <----这里写成这样就应该可以自动生成了吧?
            </id>应该是type="String"吧,你的generator生成的是16进制uuid呀