spring2.5+hibernate3.2+struts2.0插入数据时调用两次sql语句
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring2.5+hibernate3.2+struts2.0插入数据时调用两次sql语句相关的知识,希望对你有一定的参考价值。
我使用Myeclipse自动生成的函数,getHibernateTemplate().save(),执行结果如下,每次都插入两条一样的数据 ,求高手指点下啊!
Hibernate: select flower0_.flo_id as flo1_3_0_, flower0_.flo_name as flo2_3_0_, flower0_.image as image3_0_, flower0_.price as price3_0_, flower0_.describes as describes3_0_, flower0_.store as store3_0_, flower0_.commend as commend3_0_, flower0_.object as object3_0_, flower0_.material as material3_0_, flower0_.uses as uses3_0_, flower0_.festival as festival3_0_, flower0_.click as click3_0_ from flower.dbo.flower flower0_ where flower0_.flo_id=?
Hibernate: select flower0_.flo_id as flo1_3_0_, flower0_.flo_name as flo2_3_0_, flower0_.image as image3_0_, flower0_.price as price3_0_, flower0_.describes as describes3_0_, flower0_.store as store3_0_, flower0_.commend as commend3_0_, flower0_.object as object3_0_, flower0_.material as material3_0_, flower0_.uses as uses3_0_, flower0_.festival as festival3_0_, flower0_.click as click3_0_ from flower.dbo.flower flower0_ where flower0_.flo_id=?
action=nullHibernate: insert into flower.dbo.customer (cus_name, password, tel, email, qq, address, cus_id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into flower.dbo.orders (cus_id, totalprice, pay_money, pay_way, deliver_way, require_deliver_time, fact_deliver_time, deliver_case, receive_peo_name, receive_address, bless_world, receive_tel, order_peo_name, order_peo_tel, isanonymity, order_peo_email, order_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: select orderitem0_.orderitem_id as orderitem1_2_0_, orderitem0_.order_id as order2_2_0_, orderitem0_.flo_id as flo3_2_0_, orderitem0_.quantity as quantity2_0_, orderitem0_.order_date as order5_2_0_ from flower.dbo.orderitem orderitem0_ where orderitem0_.orderitem_id=?
Hibernate: select orderitem_.orderitem_id, orderitem_.order_id as order2_2_, orderitem_.flo_id as flo3_2_, orderitem_.quantity as quantity2_, orderitem_.order_date as order5_2_ from flower.dbo.orderitem orderitem_ where orderitem_.orderitem_id=?
Hibernate: insert into flower.dbo.customer (cus_name, password, tel, email, qq, address, cus_id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into flower.dbo.orderitem (order_id, flo_id, quantity, order_date, orderitem_id) values (?, ?, ?, ?, ?)
Hibernate: insert into flower.dbo.orders (cus_id, totalprice, pay_money, pay_way, deliver_way, require_deliver_time, fact_deliver_time, deliver_case, receive_peo_name, receive_address, bless_world, receive_tel, order_peo_name, order_peo_tel, isanonymity, order_peo_email, order_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: select orderitem0_.orderitem_id as orderitem1_2_0_, orderitem0_.order_id as order2_2_0_, orderitem0_.flo_id as flo3_2_0_, orderitem0_.quantity as quantity2_0_, orderitem0_.order_date as order5_2_0_ from flower.dbo.orderitem orderitem0_ where orderitem0_.orderitem_id=?
Hibernate: update flower.dbo.orderitem set order_id=?, flo_id=?, quantity=?, order_date= where orderitem_id=
Spring + Hibernate + Spring Security 配置
【中文标题】Spring + Hibernate + Spring Security 配置【英文标题】:Spring + Hibernate + Spring Security configs 【发布时间】:2012-01-23 22:18:12 【问题描述】:我有一个应用程序,它使用 Spring、Hibernate 和 Spring Security。我的目标是为这些框架中的每一个提供一个配置 (.xml) 文件并且只加载一次。所以基本上我想要spring-config.xml
、hibernate-config.xml
、spring-security.xml
和web.xml
作为配置文件。它现在可以按我的意愿工作,但是当我查看部署日志时,显然有重复的条目 - 加载了不止一次的 bean。
web.xml
- http://pastebin.com/7ELvV8fS
spring-config.xml
- http://pastebin.com/FVTcNu7L
hibernate-config.xml
- http://pastebin.com/xXWbgAex
spring-security.xml
- http://pastebin.com/JUycGUNA
GlassFish 3.1 部署输出 - http://pastebin.com/53Bgyj2r
正如您在输出中看到的,spring-config.xml
很少被启动。我在spring-config.xml
中的自定义 bean 也被启动了两次。
【问题讨论】:
检查您的服务器配置,您是否将 2 个应用程序加载到容器中? 服务器配置一切正常。我已经做到了这一点:如果我从 spring-security 配置中删除发生这种情况是因为您正在通过
在 Spring-security 中再次加载 spring-config <beans:import resource="/hibernate-config.xml"/>
<beans:import resource="/spring-config.xml"/>
您可以尝试删除此 .通过以下配置,您无需为 spring-security 指定单独的上下文参数。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/spring-security.xml,
classpath:spring/spring-config.xml
</param-value>
</context-param>
【讨论】:
以上是关于spring2.5+hibernate3.2+struts2.0插入数据时调用两次sql语句的主要内容,如果未能解决你的问题,请参考以下文章