`

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>



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics