| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use data access technologies. This module deals with enhanced support for JPA based data access layers.
This README as well as the reference documentation are the best places to start learning about Spring Data JPA. There are also two sample applications available to look at.
The main project website contains links to basic project information such as source code, JavaDocs, Issue tracking, etc.
For more detailed questions, use the forum. If you are new to Spring as well as to Spring Data, look for information about Spring projects.
Download the jar though Maven:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>Also include your JPA persistence provider of choice (Hibernate, EclipseLink, OpenJpa). Setup basic Spring JPA configuration as well as Spring Data JPA repository support.
<?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:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<jdbc:embedded-database id="dataSource" type="HSQL" />
<jpa:repositories base-package="com.acme.repositories" />
</beans>Create an entity:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String firstname;
private String lastname;
// Getters and setters
}Create a repository interface in com.acme.repositories:
public interface UserRepository extends CrudRepository<User, Long> {
List<User> findByLastname(String lastname);
}Write a test client
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:your-config-file.xml")
public class UserRepositoryIntegrationTest {
@Autowired UserRepository repository;
@Test
public void sampleTestCase() {
User dave = new User("Dave", "Matthews");
repository.save(user);
User carter = new User("Carter", "Beauford");
repository.save(carter);
List<User> result = repository.findByLastname("Matthews");
assertThat(result.size(), is(1));
assertThat(result, hasItem(dave));
}
}Here are some ways for you to get involved in the community:
Before we accept a non-trivial patch or pull request we will need you to sign the contributor's agreement. Signing the contributor's agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors might be asked to join the core team, and given the ability to merge pull requests.
| Back | FazBrowse Home | New Git URL |