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,请高手帮忙!
<!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,请高手帮忙!
解决方案 »
- 用maven构建 spring mvc 项目启动报错
- 关于Comparator
- jquery + freemark + struts2 如何实现成功操作的提示呢
- 我到Hibernate官方网站下的middlegen-hibernate包,怎么用winrar解压缩不了啊?这是什么原因啊?
- 读取hibernate表结构的问题
- java实现linux的ping命令问题
- validator框架验证通过,为啥就不能跳转到其他的jsp页面呢?
- 如何用Struts的标记库来在网页中显示某一个数据表中的数据?
- 在Struts中,怎样在一个页面修改后,更新另外一个页面?
- 怎么实现Socket文件传输时的断点续传呢?
- 闷,谁来帮帮我
- 找不到创建的cookie
<property name="connection.autocommit">true</property>
你的数据应该是存在了缓存中,没有放入数据库。估计你们的都是这个问题。好运!
http://topic.csdn.net/u/20090518/16/b9cb4da7-dfe3-4e1e-a575-adb7c07f7ab2.html
谢谢了!!
<property name="connection.autocommit">true </property>
你的数据应该是存在了缓存中,没有放入数据库。 估计你们的都是这个问题。好运!如果这样的话不是就直接提交了吗?有异常时还会回滚吗?
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;
}
}
});