spring data demo


import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity
@Table(name = "AAA")
public class LogDetail implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name = "SEQ_NO")
@SequenceGenerator(name = "generatorName", sequenceName = "MySeqName")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generatorName")
private Long seqNo;

@Lob()
@Column(name = "CONTENT", columnDefinition = "CLOB")
private String content;

@Column(name = "STATUS")
private String status;

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "SEND_DATE")
private Date sendDate;

}

}






import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Embeddable
public class CustomerPK implements Serializable{

private String code;

private String currency;

}






import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface LogRepository extends CrudRepository<Log, Long> {

@Modifying
@Query("update Log set status = 0 where id = :id ")
void batchUpdate(@Param("id") Long id);

}





<?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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
">

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
</bean>

<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="database" value="ORACLE" />
</bean>
</property>
<property name="persistenceUnitName" value="demo.unit" />
<property name="persistenceUnitPostProcessors">
<list>
<ref bean="sstsPersistenceUnitPostProcessor" />
</list>
</property>
</bean>

<bean id="em" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="emf" />
</bean>
<bean id="demoPersistenceUnitPostProcessor" class="com.xx.DemoPersistenceUnitPostProcessor">
<property name="mappingFileNames">
<list>
<value>META-INF/entity/${instance.name}/Person.orm.xml</value>
</list>
</property>
</bean>


<!-- Translate Hibernate or JPA exceptions to Spring's generic DataAccessException. -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

<!-- bean post-processor for JPA annotations -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<!-- jdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>

<bean id="jdbcDao" class="com.xx.spring.JdbcDao">
<property name="jdbcTemplate">
<ref bean="jdbcTemplate" />
</property>
</bean>

</beans>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值