详解spring整合hibernate的方法

网友投稿 213 2022-12-15


详解spring整合hibernate的方法

结构:

Spring和Hibernate整合借助于HibernateTemplate

applicationContext.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:aop="http://springframework.org/schema/aop"

xmlns:tx="http://springframework.org/schema/tx"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="

http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans-3.0.xsd

http://springframework.org/schema/aop

http://springframework.org/schema/aop/spring-aop-3.0.xsd

http://springframework.org/schema/tx

http://springframework.org/schema/tx/spring-tx-3.0.xsd

http://springframework.org/schema/context

http://springframework.org/schema/context/spring-context-3.0.xsd">

class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

com/lc/pojo/Category.hbm.xml

hibernate.dialect=org.hibernate.dialect.mysqlDialect

hibernate.show_sql=true

hbm2ddl.auto=update

class="org.springframework.jdbc.datasource.DriverManagerDataSource">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:aop="http://springframework.org/schema/aop"

xmlns:tx="http://springframework.org/schema/tx"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="

http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans-3.0.xsd

http://springframework.org/schema/aop

http://springframework.org/schema/aop/spring-aop-3.0.xsd

http://springframework.org/schema/tx

http://springframework.org/schema/tx/spring-tx-3.0.xsd

http://springframework.org/schema/context

http://springframework.org/schema/context/spring-context-3.0.xsd">

class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

com/lc/pojo/Category.hbm.xml

hibernate.dialect=org.hibernate.dialect.mysqlDialect

hibernate.show_sql=true

hbm2ddl.auto=update

class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

com/lc/pojo/Category.hbm.xml

hibernate.dialect=org.hibernate.dialect.mysqlDialect

hibernate.show_sql=true

hbm2ddl.auto=update

class="org.springframework.jdbc.datasource.DriverManagerDataSource">

class="org.springframework.jdbc.datasource.DriverManagerDataSource">

测试:

ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");

CategoryDAO bean =(CategoryDAO) context.getBean("dao");

DetachedCriteria criteria = DetachedCriteria.forClass(Category.class);

// List list = bean.findByCriteria(criteria, 0, 5); //分页--取0-5个返回

// System.out.println(list);

Category.hbm.xml

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">

result:

总结

以上所述是给大家介绍的spring整合hibernate的方法,希望对大家有所帮助!http://


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:在eclipse中安装Scala环境的步骤详解
下一篇:Java中的强制类型转换 大数转小数
相关文章

 发表评论

暂时没有评论,来抢沙发吧~