当前位置: 代码迷 >> J2SE >> 急求助!Hibernate中遇到Could not synchronize database state with session有关问题
  详细解决方案

急求助!Hibernate中遇到Could not synchronize database state with session有关问题

热度:436   发布时间:2016-04-24 15:45:39.0
急!求助!Hibernate中遇到Could not synchronize database state with session问题
映射文件:
<hibernate-mapping   package= "bean.admin.order ">
    <class   name= "Order "   table= "order ">
        <id   name= "oid "   column= "oid ">
            <generator   class= "uuid.hex ">              
            </generator>
        </id>
       
        <property   name= "name "   length= "20 "/>
        <property   name= "pay "/>
        <property   name= "deliver "/>
        <property   name= "adds "   type= "string "   length= "100 "/>
        <property   name= "postCode "   type= "string "   length= "10 "/>
        <property   name= "phone "   type= "string "   length= "20 "/>
        <property   name= "email "   length= "50 "/>  
        <property   name= "summed "/>
        <property   name= "state "/>
        <property   name= "regdate "/>

    </class>
</hibernate-mapping>

bean:
public   class   Order   {

private   String   oid;

private   String   name;
private   int   pay;
private   int   deliver;
private   String   adds;
private   String   postCode;
private   String   phone;
private   String   email;
private   float   summed;
private   int   state;
private   Date   regdate;
              //省略get()   set()
}

DAO:
public   class   OrderDao   {
public   int   newOrder(Order   order){
SessionFactory   sessionfactory=HibernateUtil.getSessionFactory();
Session   session=sessionfactory.openSession();

try{
session.beginTransaction();
session.save(order);
session.getTransaction().commit();
return   0;
}catch(Exception   e){
e.printStackTrace();
return   -9;
}
}
}

public   class   Test   {
public   static   void   main(String   args[]){
OrderDao   orderdao=new   OrderDao();
int   ret;
Order   order=new   Order();
order.setName( "zsy ");
order.setAdminid( "gemini ");
order.setPhone( "123546798 ");
order.setRegdate(new   Date());
ret=orderdao.newOrder(order);
System.out.println(ret);

}
}

结果每次运行的时候都是
Hibernate:   insert   into   order   (name,   pay,   deliver,   adds,   postCode,   phone,   email,   summed,   state,   regdate,   oid)   values   (?,   ?,   ?,   ?,   ?,   ?,   ?,   ?,   ?,   ?,   ?)
  相关解决方案