JAVA-143: Migrate spring-jpa to com.baeldung

This commit is contained in:
Krzysztof Woyke 2020-02-18 12:42:05 +01:00
parent 173440f519
commit 4cb11e3945
51 changed files with 102 additions and 102 deletions

View File

@ -4,13 +4,13 @@
### Relevant Articles:
- [The DAO with JPA and Spring](http://www.baeldung.com/spring-dao-jpa)
- [JPA Pagination](http://www.baeldung.com/jpa-pagination)
- [Sorting with JPA](http://www.baeldung.com/jpa-sort)
- [Self-Contained Testing Using an In-Memory Database](http://www.baeldung.com/spring-jpa-test-in-memory-database)
- [A Guide to Spring AbstractRoutingDatasource](http://www.baeldung.com/spring-abstract-routing-data-source)
- [Obtaining Auto-generated Keys in Spring JDBC](http://www.baeldung.com/spring-jdbc-autogenerated-keys)
- [Transactions with Spring 4 and JPA](http://www.baeldung.com/transaction-configuration-with-jpa-and-spring)
- [The DAO with JPA and Spring](https://www.baeldung.com/spring-dao-jpa)
- [JPA Pagination](https://www.baeldung.com/jpa-pagination)
- [Sorting with JPA](https://www.baeldung.com/jpa-sort)
- [Self-Contained Testing Using an In-Memory Database](https://www.baeldung.com/spring-jpa-test-in-memory-database)
- [A Guide to Spring AbstractRoutingDatasource](https://www.baeldung.com/spring-abstract-routing-data-source)
- [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys)
- [Transactions with Spring 4 and JPA](https://www.baeldung.com/transaction-configuration-with-jpa-and-spring)
- [Use Criteria Queries in a Spring Data Application](https://www.baeldung.com/spring-data-criteria-queries)
- [Many-To-Many Relationship in JPA](https://www.baeldung.com/jpa-many-to-many)
- [Spring Persistence (Hibernate and JPA) with a JNDI datasource](https://www.baeldung.com/spring-persistence-hibernate-and-jpa-with-a-jndi-datasource/)

View File

@ -1,4 +1,4 @@
package org.baeldung.annotations;
package com.baeldung.annotations;
import java.io.Serializable;
import java.util.Optional;

View File

@ -1,4 +1,4 @@
package org.baeldung.annotations;
package com.baeldung.annotations;
import java.util.Date;
@ -8,7 +8,7 @@ import javax.persistence.NamedStoredProcedureQuery;
import javax.persistence.ParameterMode;
import javax.persistence.StoredProcedureParameter;
import org.baeldung.persistence.multiple.model.user.User;
import com.baeldung.persistence.multiple.model.user.User;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;

View File

@ -1,4 +1,4 @@
package org.baeldung.annotations;
package com.baeldung.annotations;
import javax.persistence.LockModeType;

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import java.util.Properties;
@ -25,8 +25,8 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-h2.properties" })
@ComponentScan({ "org.baeldung.persistence" })
@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao")
@ComponentScan({ "com.baeldung.persistence" })
@EnableJpaRepositories(basePackages = "com.baeldung.persistence.dao")
public class PersistenceJPAConfig {
@Autowired
@ -42,7 +42,7 @@ public class PersistenceJPAConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
@ -6,7 +6,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
// @Configuration
@EnableTransactionManagement
@ComponentScan({ "org.baeldung.persistence" })
@ComponentScan({ "com.baeldung.persistence" })
@ImportResource({ "classpath:jpaConfig.xml" })
public class PersistenceJPAConfigXml {

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -10,7 +10,7 @@ import org.springframework.web.servlet.view.JstlView;
@EnableWebMvc
@Configuration
@ComponentScan({ "org.baeldung.web" })
@ComponentScan({ "com.baeldung.web" })
public class SpringWebConfig extends WebMvcConfigurerAdapter {
@Bean

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import java.util.Properties;
@ -18,7 +18,7 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableJpaRepositories(basePackages = "org.baeldung.inmemory.persistence.dao")
@EnableJpaRepositories(basePackages = "com.baeldung.inmemory.persistence.dao")
@PropertySource("persistence-student.properties")
@EnableTransactionManagement
public class StudentJpaConfig {
@ -41,7 +41,7 @@ public class StudentJpaConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "org.baeldung.inmemory.persistence.model" });
em.setPackagesToScan(new String[] { "com.baeldung.inmemory.persistence.model" });
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
em.setJpaProperties(additionalProperties());
return em;

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

View File

@ -1,4 +1,4 @@
package org.baeldung.dsrouting;
package com.baeldung.dsrouting;
import javax.sql.DataSource;

View File

@ -1,4 +1,4 @@
package org.baeldung.dsrouting;
package com.baeldung.dsrouting;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

View File

@ -1,4 +1,4 @@
package org.baeldung.dsrouting;
package com.baeldung.dsrouting;
public enum ClientDatabase {

View File

@ -1,4 +1,4 @@
package org.baeldung.dsrouting;
package com.baeldung.dsrouting;
/**
* Service layer code for datasource routing example. Here, the service methods are responsible

View File

@ -1,6 +1,6 @@
package org.baeldung.inmemory.persistence.dao;
package com.baeldung.inmemory.persistence.dao;
import org.baeldung.inmemory.persistence.model.ManyStudent;
import com.baeldung.inmemory.persistence.model.ManyStudent;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;

View File

@ -1,6 +1,6 @@
package org.baeldung.inmemory.persistence.dao;
package com.baeldung.inmemory.persistence.dao;
import org.baeldung.inmemory.persistence.model.ManyTag;
import com.baeldung.inmemory.persistence.model.ManyTag;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ManyTagRepository extends JpaRepository<ManyTag, Long> {

View File

@ -1,6 +1,6 @@
package org.baeldung.inmemory.persistence.dao;
package com.baeldung.inmemory.persistence.dao;
import org.baeldung.inmemory.persistence.model.Student;
import com.baeldung.inmemory.persistence.model.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

View File

@ -1,4 +1,4 @@
package org.baeldung.inmemory.persistence.model;
package com.baeldung.inmemory.persistence.model;
import javax.persistence.Embeddable;

View File

@ -1,4 +1,4 @@
package org.baeldung.inmemory.persistence.model;
package com.baeldung.inmemory.persistence.model;
import javax.persistence.Embeddable;

View File

@ -1,4 +1,4 @@
package org.baeldung.inmemory.persistence.model;
package com.baeldung.inmemory.persistence.model;
import javax.persistence.*;
import java.util.HashSet;

View File

@ -1,4 +1,4 @@
package org.baeldung.inmemory.persistence.model;
package com.baeldung.inmemory.persistence.model;
import javax.persistence.*;
import java.util.HashSet;

View File

@ -1,4 +1,4 @@
package org.baeldung.inmemory.persistence.model;
package com.baeldung.inmemory.persistence.model;
import javax.persistence.Embeddable;

View File

@ -1,4 +1,4 @@
package org.baeldung.inmemory.persistence.model;
package com.baeldung.inmemory.persistence.model;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import java.io.Serializable;
import java.util.List;

View File

@ -1,6 +1,6 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import org.baeldung.persistence.model.Book;
import com.baeldung.persistence.model.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

View File

@ -1,8 +1,8 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import java.util.List;
import org.baeldung.persistence.model.Book;
import com.baeldung.persistence.model.Book;
public interface BookRepositoryCustom {

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import java.util.ArrayList;
import java.util.List;
@ -10,7 +10,7 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.baeldung.persistence.model.Book;
import com.baeldung.persistence.model.Book;
import org.springframework.stereotype.Repository;
@Repository

View File

@ -1,12 +1,12 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import static org.baeldung.persistence.dao.BookSpecifications.hasAuthor;
import static org.baeldung.persistence.dao.BookSpecifications.titleContains;
import static com.baeldung.persistence.dao.BookSpecifications.hasAuthor;
import static com.baeldung.persistence.dao.BookSpecifications.titleContains;
import static org.springframework.data.jpa.domain.Specifications.where;
import java.util.List;
import org.baeldung.persistence.model.Book;
import com.baeldung.persistence.model.Book;
import org.springframework.stereotype.Service;
@Service

View File

@ -1,6 +1,6 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import org.baeldung.persistence.model.Book;
import com.baeldung.persistence.model.Book;
import org.springframework.data.jpa.domain.Specification;
public class BookSpecifications {

View File

@ -1,6 +1,6 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import org.baeldung.persistence.model.Foo;
import com.baeldung.persistence.model.Foo;
import org.springframework.stereotype.Repository;
@Repository

View File

@ -1,8 +1,8 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import java.util.List;
import org.baeldung.persistence.model.Foo;
import com.baeldung.persistence.model.Foo;
public interface IFooDao {

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.model;
package com.baeldung.persistence.model;
import java.io.Serializable;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.model;
package com.baeldung.persistence.model;
import javax.persistence.Entity;
import javax.persistence.Id;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.model;
package com.baeldung.persistence.model;
import org.hibernate.annotations.CacheConcurrencyStrategy;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.multiple.model.user;
package com.baeldung.persistence.multiple.model.user;
import javax.persistence.*;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.multiple.model.user;
package com.baeldung.persistence.multiple.model.user;
import javax.persistence.*;
import java.util.List;

View File

@ -1,9 +1,9 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import java.util.List;
import org.baeldung.persistence.dao.IFooDao;
import org.baeldung.persistence.model.Foo;
import com.baeldung.persistence.dao.IFooDao;
import com.baeldung.persistence.model.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

View File

@ -1,4 +1,4 @@
package org.baeldung.sqlfiles;
package com.baeldung.sqlfiles;
import static javax.persistence.GenerationType.IDENTITY;

View File

@ -1,6 +1,6 @@
package org.baeldung.web;
package com.baeldung.web;
import org.baeldung.persistence.service.FooService;
import com.baeldung.persistence.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

View File

@ -11,7 +11,7 @@
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="org.baeldung.persistence.model"/>
<property name="packagesToScan" value="com.baeldung.persistence.model"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
<!-- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /> <property name="generateDdl" value="${jpa.generateDdl}" /> <property name="databasePlatform"

View File

@ -3,8 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="punit">
<class>org.baeldung.persistence.model.Foo</class>
<class>org.baeldung.persistence.model.Bar</class>
<class>com.baeldung.persistence.model.Foo</class>
<class>com.baeldung.persistence.model.Bar</class>
<properties>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>

View File

@ -1,6 +1,6 @@
package com.baeldung;
import org.baeldung.config.PersistenceJPAConfig;
import com.baeldung.config.PersistenceJPAConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;

View File

@ -1,14 +1,14 @@
package org.baeldung.persistence.repository;
package com.baeldung.persistence.repository;
import org.baeldung.config.StudentJpaConfig;
import org.baeldung.inmemory.persistence.dao.ManyStudentRepository;
import org.baeldung.inmemory.persistence.dao.ManyTagRepository;
import org.baeldung.inmemory.persistence.dao.StudentRepository;
import org.baeldung.inmemory.persistence.model.KVTag;
import org.baeldung.inmemory.persistence.model.ManyStudent;
import org.baeldung.inmemory.persistence.model.ManyTag;
import org.baeldung.inmemory.persistence.model.SkillTag;
import org.baeldung.inmemory.persistence.model.Student;
import com.baeldung.config.StudentJpaConfig;
import com.baeldung.inmemory.persistence.dao.ManyStudentRepository;
import com.baeldung.inmemory.persistence.dao.ManyTagRepository;
import com.baeldung.inmemory.persistence.dao.StudentRepository;
import com.baeldung.inmemory.persistence.model.ManyStudent;
import com.baeldung.inmemory.persistence.model.ManyTag;
import com.baeldung.inmemory.persistence.model.SkillTag;
import com.baeldung.inmemory.persistence.model.Student;
import com.baeldung.inmemory.persistence.model.KVTag;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;

View File

@ -1,8 +1,8 @@
package org.baeldung.persistence.repository;
package com.baeldung.persistence.repository;
import org.baeldung.config.StudentJpaConfig;
import org.baeldung.inmemory.persistence.dao.StudentRepository;
import org.baeldung.inmemory.persistence.model.Student;
import com.baeldung.config.StudentJpaConfig;
import com.baeldung.inmemory.persistence.dao.StudentRepository;
import com.baeldung.inmemory.persistence.model.Student;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.Matchers.hasSize;
@ -15,8 +15,8 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.baeldung.config.PersistenceJPAConfig;
import org.baeldung.persistence.model.Foo;
import com.baeldung.config.PersistenceJPAConfig;
import com.baeldung.persistence.model.Foo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,9 +1,9 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import org.baeldung.config.PersistenceJPAConfig;
import org.baeldung.persistence.model.Foo;
import com.baeldung.config.PersistenceJPAConfig;
import com.baeldung.persistence.model.Foo;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import java.util.List;
@ -10,9 +10,9 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.baeldung.config.PersistenceJPAConfig;
import org.baeldung.persistence.model.Bar;
import org.baeldung.persistence.model.Foo;
import com.baeldung.config.PersistenceJPAConfig;
import com.baeldung.persistence.model.Bar;
import com.baeldung.persistence.model.Foo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.junit.Assert.assertNull;
@ -9,8 +9,8 @@ import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.baeldung.config.PersistenceJPAConfig;
import org.baeldung.persistence.model.Foo;
import com.baeldung.config.PersistenceJPAConfig;
import com.baeldung.persistence.model.Foo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;