1
votes

I am searching for the simplest working example of spring controlled JPA(insert,update, delete).

I already found and tried many, still they not simple enough: - http://spring.io/guides/gs/accessing-data-jpa/ - http://www.petrikainulainen.net/tutorials/

Prefereble easy to import so I could check it easly.

They find ok. Still persistance is not simplified enough.

2

2 Answers

0
votes

I think insert and update of database data is simplified in http://www.mkyong.com/spring/spring-aop-transaction-management-in-hibernate/ From that change into delete is easy enough to me.

Then we can change Hibernate.xml to simpler mapping:

     <bean id="sessionFactory" 
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

     <property name="annotatedClasses">
        <list>
         <value>com.mkyong.product.model.Product</value>
        </list>
     </property>
0
votes

http://www.java2s.com/Tutorials/Java/JPA/0020__JPA_Env_Setup.htm

Then add table Person to database(id (int autoincrement), name, surname), change url, change dialect in hibernate.dialect (ex. org.hibernate.dialect.MySQLDialect) and it works.

Then to make it work with Spring Data config as below

package com.java2s.common; 
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@EnableJpaRepositories
class Config {}

Or configure in xml context(src/main/resources/applicationContext.xml) add //schema releated entry, xmlns:jpa and <jpa:repositories base-package="com.java2s.common"/>

Place App.java in package other than com.java2s.common. In pom.xml if U want latest version:

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.7.1.RELEASE</version>
    </dependency>

I and updated all spring dependencies to 4.0.2.RELEASE, for spring version 3 U will need spring-data-jpa in version 1.6.4.RELEASE.