hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433;databasename=netshop</property>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.cp30.min_size">5</property>
<property name="hibernate.cp30.max_size">20</property>
<property name="hibernate.cp30.timeout">300</property>
<property name="hibernate.max_statements">50</property>
<property name="hibernate.cp30.idle_test_period">3000</property>

<mapping resource="cn/edu/zzu/model/User.hbm.xml"/>
<mapping resource="cn/edu/zzu/model/Manger.hbm.xml"/>
<mapping resource="cn/edu/zzu/model/Item.hbm.xml"/>
<mapping resource="cn/edu/zzu/model/Admin.hbm.xml"/>
<mapping resource="cn/edu/zzu/model/Order.hbm.xml"/>
</session-factory>
</hibernate-configuration>
ExportDB.java
package cn.edu.zzu.util;import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;public class ExportDB { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();

SchemaExport export = new SchemaExport(cfg);

export.create(true, true);
}}我执行ExportDB导出表,会出现以下警告
alter table order_item drop constraint FK2D110D6434906693
alter table order_item drop constraint FK2D110D64612D8C61
alter table t_orders drop constraint FK7757B510ADAE0B93
drop table order_item
drop table t_admins
drop table t_items
drop table t_mangers
drop table t_orders
drop table t_users
create table order_item (Order_Id int not null, Item_Id int not null, Position int not null, primary key (Order_Id, Position))
create table t_admins (id int identity not null, name varchar(255) not null, passWord varchar(255) not null, age int not null, sex varchar(255) not null, phone varchar(255) null, cellPhone varchar(255) null, primary key (id))
create table t_items (id int identity not null, itemName varchar(255) not null, price float not null, quantity int not null, image varbinary(255) null, primary key (id))
create table t_mangers (id int identity not null, name varchar(255) not null, passWord varchar(255) not null, age int not null, sex varchar(255) not null, phone varchar(255) null, cellPhone varchar(255) null, primary key (id))
create table t_orders (id int identity not null, totalPrice float not null, isSend tinyint not null, USER_ID int null, primary key (id))
create table t_users (id int identity not null, name varchar(255) not null, passWord varchar(255) not null, age int not null, sex varchar(255) not null, address varchar(255) not null, phone varchar(255) null, cellPhone varchar(255) null, email varchar(255) not null, primary key (id))
alter table order_item add constraint FK2D110D6434906693 foreign key (Item_Id) references t_items
alter table order_item add constraint FK2D110D64612D8C61 foreign key (Order_Id) references t_orders
alter table t_orders add constraint FK7757B510ADAE0B93 foreign key (USER_ID) references t_users
21:57:15,484  WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 
21:57:15,515  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to netshop
21:57:15,515  WARN JDBCExceptionReporter:48 - SQL Warning: 5701, SQLState: 01000
21:57:15,515  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]已将数据库上下文改为 'netshop'。
21:57:15,515  WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 
21:57:15,515  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to 简体中文
21:57:15,515  WARN JDBCExceptionReporter:48 - SQL Warning: 5703, SQLState: 01000
21:57:15,515  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]已将语言设置改为 简体中文。当我想在t_items表中插入一条数据的时候会出现以下警告
Hibernate: insert into t_items (itemName, price, quantity, image) values (?, ?, ?, ?) select scope_identity()
21:58:46,265  WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 
21:58:46,265  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to netshop
21:58:46,265  WARN JDBCExceptionReporter:48 - SQL Warning: 5701, SQLState: 01000
21:58:46,265  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]已将数据库上下文改为 'netshop'。
21:58:46,265  WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 
21:58:46,265  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to 简体中文
21:58:46,265  WARN JDBCExceptionReporter:48 - SQL Warning: 5703, SQLState: 01000
21:58:46,281  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]已将语言设置改为 简体中文。但是在数据库中却查询不到插入的数据,在查询分析器中写insert语句可以插入,并且主键会增加1,请高手帮忙!

解决方案 »

  1.   

    警告并不会影响插入操作,你上面的sql都是没有错的,我看最大的可能就是事物没有提交,导致数据库里的数据没有更新。
      

  2.   

    可能是你的框架版本不同     如果是插入的话就我知道有两种方式:一种是:super.getSession().save(object);另一种是:super.getHibernateTemplate().saveOrUpdate(object);我也遇到同样的问题  我提交能成功也不报错  就是不能插入数据库里面.
      

  3.   

    你们的dao是myeclipse自动生成的吧? 在hibernate.cfg.xml的配置中加一条语句看看:
    <property name="connection.autocommit">true</property>
    你的数据应该是存在了缓存中,没有放入数据库。估计你们的都是这个问题。好运!
      

  4.   

    如果你们有兴趣的话,帮我看看我的问题哦,急但解决不了(很穷没什么分),,,
    http://topic.csdn.net/u/20090518/16/b9cb4da7-dfe3-4e1e-a575-adb7c07f7ab2.html
    谢谢了!!
      

  5.   

    你们的dao是myeclipse自动生成的吧? 在hibernate.cfg.xml的配置中加一条语句看看: 
    <property name="connection.autocommit">true </property> 
    你的数据应该是存在了缓存中,没有放入数据库。 估计你们的都是这个问题。好运!如果这样的话不是就直接提交了吗?有异常时还会回滚吗?
      

  6.   

    try{
    this.getHibernateTemplate().execute(new HibernateCallback(){
    public Object doInHibernate(Session session)throws HibernateException,SQLException{
    try{



    session.beginTransaction();

                    
                    
    session.save(item);


    session.getTransaction().commit();
    return null;
    }catch(Exception e){
    e.printStackTrace();
    session.getTransaction().rollback();

    return null;
    }


    }
    });