Spring 和Hibernate集成问题?

wha263628011 2009-02-28 10:22:02
写了个简单的 集成
出现了如下问题

21:40:36,015 WARN Configurator:126 - No configuration found. Configuring ehcache from

ehcache-failsafe.xml found in the classpath: jar:file:/C:/Program%20Files/MyEclipse%205.5%

20GA/myeclipse/eclipse/plugins/com.genuitec.org.hibernate.eclipse_5.5.0/myeclipse-

data/3.0/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
21:40:36,484 WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState:
21:40:36,484 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]

Database changed to sky
21:40:36,484 WARN JDBCExceptionReporter:48 - SQL Warning: 5701, SQLState: 01000
21:40:36,484 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]

[SQLServer]已将数据库上下文改为 'sky'。
21:40:36,484 WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState:
21:40:36,484 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]

Language changed to 简体中文
21:40:36,484 WARN JDBCExceptionReporter:48 - SQL Warning: 5703, SQLState: 01000
21:40:36,484 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]

[SQLServer]已将语言设置改为 简体中文。

使得对数据库的操作无法执行 知道的告诉下 真的谢谢了


代码参见

<?xml version="1.0" encoding="UTF-8" ?>
- <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
- <bean id="guestbookDaoHibernate" class="com.guest.daoHibernate.GuestbookDaoHibernate" abstract="false" lazy-init="default" autowire="default" dependency-check="default">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
- <bean id="guestbookmanger" class="com.guest.usermangerImpl.UsermangerImpl" abstract="false" lazy-init="default" autowire="default" dependency-check="default">
<property name="guestbookDaoHibernate" ref="guestbookDaoHibernate" />
</bean>
</beans>


package com.guest.client;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import com.guest.usermangerImpl.UsermangerImpl;

public class client {

/**
* @param args
*/
public static void main(String[] args) {



BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
UsermangerImpl userManager = (UsermangerImpl)factory.getBean("guestbookmanger");
try {
userManager.delect(7);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}
...全文
87 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jumpheightway 2009-03-01
  • 打赏
  • 举报
回复
你的hibernate配置文件有问题



专业培训:JAVA J2EE JSP PHP LAMP系列架构

联系QQ:492236022
sjqzone 2009-03-01
  • 打赏
  • 举报
回复
拷贝hibernate目录的ehcache.xml文件到src目录就OK了
sjqzone 2009-03-01
  • 打赏
  • 举报
回复
如果在/sandh/web-inf/classes下面没有ehcache.xml这个文件,会报这个错误,No configuration found.

Configuring ehcache from ehcache-failsafe.xml found in the classpath:.....这个文件是hibernate缓存配置文








maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="10000"
timeToLiveSeconds="10000"
overflowToDisk="true"
/>

maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="10000"
timeToLiveSeconds="10000"
overflowToDisk="true"
/>


上面配置了默认类缓存和城市类缓存策略:

表示当内存缓存中对象数量超过类设置内存缓存数量时,将缓存对象写到硬盘,path=”java.io.tmpdir

”表示把数据写到这个目录下。Java.io.tmpdir目录在运行时会根据相对路径生成。
表示设定缓存的默认数据过期策略。
表示设定用具体的命名缓存的数据过期策略。
name表示具体的缓存命名。
maxElementsInMemory表示cache中最大允许保存的对象数据量。
eternal表示cache中数据是否为常量。
timeToIdleSeconds表示缓存数据钝化时间
timeToLiveSeconds表示缓存数据的生命时间。
overflowToDisk表示内存不足时,是否启用磁盘缓存。
wha263628011 2009-03-01
  • 打赏
  • 举报
回复
错误如下:

21:40:36,015 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Program%20Files/MyEclipse%205.5%20GA/myeclipse/eclipse/plugins/com.genuitec.org.hibernate.eclipse_5.5.0/myeclipse-data/3.0/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
21:40:36,484 WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState:
21:40:36,484 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to sky
21:40:36,484 WARN JDBCExceptionReporter:48 - SQL Warning: 5701, SQLState: 01000
21:40:36,484 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]已将数据库上下文改为 'sky'。
21:40:36,484 WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState:
21:40:36,484 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to 简体中文
21:40:36,484 WARN JDBCExceptionReporter:48 - SQL Warning: 5703, SQLState: 01000
21:40:36,484 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]已将语言设置改为 简体中文。

jar : hibernate 核心
spring核心
spring Aop



代码参见 :

配置文件 :
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>

<bean id="guestbookDaoHibernate"
class="com.guest.daoHibernate.GuestbookDaoHibernate" abstract="false"
lazy-init="default" autowire="default" dependency-check="default">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>


<bean id="guestbookmanger"
class="com.guest.usermangerImpl.UsermangerImpl" abstract="false"
lazy-init="default" autowire="default" dependency-check="default">
<property name="guestbookDaoHibernate" ref="guestbookDaoHibernate"/>
</bean>


</beans>


dao:

package com.guest.daoHibernate;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.guest.dao.GuestbookDao;
import com.usermagr.model.Guest;

public class GuestbookDaoHibernate extends HibernateDaoSupport implements
GuestbookDao {

public void delect(int id) {
Guest guest=this.getGuest(id);
this.getHibernateTemplate().delete(guest);

}

public Guest getGuest(int id) {
Guest guest=(Guest)this.getHibernateTemplate().load(Guest.class, id);
return guest;
}

public List getGuests() {
Query query=this.getSession().createQuery("from Guest");
List list=query.list();
return list;
}

public void save(Guest g) {
this.getHibernateTemplate().save(g);

}

}


客户端:
public class client {

/**
* @param args
*/
public static void main(String[] args) {



BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
UsermangerImpl userManager = (UsermangerImpl)factory.getBean("guestbookmanger");
try {
userManager.delect(7);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}




fosjos 2009-03-01
  • 打赏
  • 举报
回复
警告应该没什么问题

数据库操作报了什么错误,贴一下

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧