Hibernate3使用(三)Spring整合Hibernate自动扫描
来源:互联网 发布:大数据审批模型 编辑:程序博客网 时间:2024/06/05 14:30
1、spring xml文件配置
<?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" xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"><!-- default-autowire="byName"> --><!-- <context:annotation-config /> --><context:component-scan base-package="webHibernate"><!-- <context:include-filter type="assignable"expression="SpringStudy.Model.Counter" /> --></context:component-scan><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver" /><property name="url" value="jdbc:mysql://127.0.0.1:3306/CK0" /><property name="username" value="user" /><property name="password" value="111" /></bean> <bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="packagesToScan" value="webHibernate" /><property name="hibernateProperties"><props><prop key="dialect">org.hibernate.dialect.HSQLDialect</prop></props></property></bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <tx:annotation-driven transaction-manager="txManager"/></beans>
2、实体类
注意1:要有主键注释
注意2:表名、列名需要在注解中标注出来
package webHibernate;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.Table;@Entity@Table(name="ck_order_flow_invoice")public class OrderFlowInvoice {public OrderFlowInvoice() {}public OrderFlowInvoice(Integer id, Long orderid) {System.out.println(orderid);}@Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "id", nullable = false)private Long id;@Column(name = "order_id")private Long orderId;@Column(name = "invoice_title")private String invoiceTitle;@Column(name = "invoice_content")private String invoiceContent;public Long getId() {return id;}public void setId(Long id) {this.id = id;}public Long getOrderId() {return orderId;}public void setOrderId(Long orderId) {this.orderId = orderId;}public String getInvoiceTitle() {return invoiceTitle;}public void setInvoiceTitle(String invoiceTitle) {this.invoiceTitle = invoiceTitle == null ? null : invoiceTitle.trim();}public String getInvoiceContent() {return invoiceContent;}public void setInvoiceContent(String invoiceContent) {this.invoiceContent = invoiceContent == null ? null : invoiceContent.trim();}}
3、接口类、接口实现类、Test类
同Hibernate3使用(二)Spring整合Hibernate,使用xml配置
0 0
- Hibernate3使用(三)Spring整合Hibernate自动扫描
- Hibernate3使用(二)Spring整合Hibernate,使用xml配置
- Hibernate3使用(一)不使用Spring时使用Hibernate
- Spring与Hibernate整合(三)
- Spring+hibernate+springmvc 整合(三)
- (三)spring与Hibernate的整合
- Hibernate3注解使用与spring 整合
- 【Spring】Spring+Struts2+Hibernate3整合(十七)
- Spring整合Mybatis【自动扫描方式】
- 使用spring整合hibernate
- Spring 整合 hibernate3
- Spring学习笔记(三)----Spring整合Hibernate
- Spring(之三)-- Spring整合Struts,Hibernate
- spring 学习之三(spring 与hibernate, struts2整合)
- Spring整合MyBatis (使用扫描包配置mapper代理)
- Spring(三)Spring整合Struts2、Hibernate
- 使用spring整合hibernate、struts
- Spring基本使用:整合hibernate
- VC按钮自绘的简单实现
- C#【oledbConnection】
- Socks协议实现
- 管理时间的七个好习惯
- 多路I/O复用分析
- Hibernate3使用(三)Spring整合Hibernate自动扫描
- Android学习0827<九>(Toast、AlertDialog )
- 关键错误,开始菜单和cortana无法工作,注销重新登录我们会修复此问题?
- python 序列类型以及list(列表) 和 tuple(元组)详解 以及range的用法
- 在eclipse下部署maven
- bzoj-1146 网络管理Network
- c++—————————const
- 解决Mac上PyDev无法导入某些模块的问题
- hdu 1690 Bus System