Commit dc7b3f6d authored by Madhura Bhave's avatar Madhura Bhave

Update samples to use new generator mappings

Closes gh-7612
parent f15cf4b9
......@@ -22,6 +22,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
@Entity
public class City implements Serializable {
......@@ -29,7 +30,8 @@ public class City implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@SequenceGenerator(name="city_generator", sequenceName="city_sequence", initialValue = 23)
@GeneratedValue(generator = "city_generator")
private Long id;
@Column(nullable = false)
......
......@@ -26,6 +26,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import org.hibernate.annotations.NaturalId;
......@@ -35,7 +36,8 @@ public class Hotel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@SequenceGenerator(name="hotel_generator", sequenceName="hotel_sequence", initialValue = 28)
@GeneratedValue(generator = "hotel_generator")
private Long id;
@ManyToOne(optional = false)
......
......@@ -26,6 +26,7 @@ import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
......@@ -37,7 +38,8 @@ public class Review implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@SequenceGenerator(name="review_generator", sequenceName="review_sequence", initialValue = 64)
@GeneratedValue(generator = "review_generator")
private Long id;
@ManyToOne(optional = false)
......
......@@ -48,8 +48,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest
// Enable JMX so we can test the MBeans (you can't do this in a properties file)
@TestPropertySource(properties = { "spring.jmx.enabled:true",
"spring.datasource.jmx-enabled:true",
"spring.jpa.hibernate.use-new-id-generator-mappings=false" })
"spring.datasource.jmx-enabled:true" })
@ActiveProfiles("scratch")
// Separate profile for web tests to avoid clashing databases
public class SampleDataJpaApplicationTests {
......
......@@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -35,7 +34,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
public class CityRepositoryIntegrationTests {
@Autowired
......
......@@ -30,7 +30,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -42,7 +41,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
public class HotelRepositoryIntegrationTests {
@Autowired
......
......@@ -22,6 +22,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
@Entity
public class City implements Serializable {
......@@ -29,7 +30,8 @@ public class City implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@SequenceGenerator(name="city_generator", sequenceName="city_sequence", initialValue = 23)
@GeneratedValue(generator = "city_generator")
private Long id;
@Column(nullable = false)
......
......@@ -23,6 +23,7 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import org.hibernate.annotations.NaturalId;
......@@ -32,7 +33,8 @@ public class Hotel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@SequenceGenerator(name="hotel_generator", sequenceName="hotel_sequence", initialValue = 28)
@GeneratedValue(generator = "hotel_generator")
private Long id;
@ManyToOne(optional = false)
......
......@@ -22,8 +22,6 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
......@@ -45,8 +43,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
@ActiveProfiles("scratch")
// Separate profile for web tests to avoid clashing databases
public class SampleDataRestApplicationTests {
......
......@@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -37,7 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
public class CityRepositoryIntegrationTests {
@Autowired
......
......@@ -19,11 +19,13 @@ package sample.flyway;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
@Entity
public class Person {
@Id
@GeneratedValue
@SequenceGenerator(name="person_generator", sequenceName="person_sequence", allocationSize = 1)
@GeneratedValue(generator = "person_generator")
private Long id;
private String firstName;
private String lastName;
......
......@@ -4,4 +4,6 @@ CREATE TABLE PERSON (
last_name varchar(255) not null
);
create sequence person_sequence start with 1 increment by 1;
insert into PERSON (first_name, last_name) values ('Dave', 'Syer');
\ No newline at end of file
......@@ -22,14 +22,12 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
public class SampleFlywayApplicationTests {
@Autowired
......
......@@ -20,15 +20,16 @@ import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
@Entity
public class Note {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@SequenceGenerator(name="note_generator", sequenceName="note_sequence", initialValue = 5)
@GeneratedValue(generator = "note_generator")
private long id;
private String title;
......
......@@ -23,12 +23,14 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
@Entity
public class Tag {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@SequenceGenerator(name="tag_generator", sequenceName="tag_sequence", initialValue = 4)
@GeneratedValue(generator = "tag_generator")
private long id;
private String name;
......
insert into tag(name) values ('Spring projects')
insert into tag(name) values ('Apache projects')
insert into tag(name) values ('Open source')
insert into tag(id, name) values (1, 'Spring projects')
insert into tag(id, name) values (2, 'Apache projects')
insert into tag(id, name) values (3, 'Open source')
insert into note(title, body) values ('Spring Boot', 'Takes an opinionated view of building production-ready Spring applications.')
insert into note(title, body) values ('Spring Framework', 'Core support for dependency injection, transaction management, web applications, data access, messaging, testing and more.')
insert into note(title, body) values ('Spring Integration', 'Extends the Spring programming model to support the well-known Enterprise Integration Patterns.')
insert into note(title, body) values ('Tomcat', 'Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies.')
insert into note(id, title, body) values (1, 'Spring Boot', 'Takes an opinionated view of building production-ready Spring applications.')
insert into note(id, title, body) values (2, 'Spring Framework', 'Core support for dependency injection, transaction management, web applications, data access, messaging, testing and more.')
insert into note(id, title, body) values (3, 'Spring Integration', 'Extends the Spring programming model to support the well-known Enterprise Integration Patterns.')
insert into note(id, title, body) values (4, 'Tomcat', 'Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies.')
insert into note_tags(notes_id, tags_id) values (1, 1)
insert into note_tags(notes_id, tags_id) values (2, 1)
......
......@@ -22,7 +22,6 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
......@@ -41,7 +40,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
@WebAppConfiguration
public class SampleJpaApplicationTests {
......
......@@ -23,7 +23,6 @@ import sample.jpa.domain.Note;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
......@@ -36,7 +35,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
@Transactional
public class JpaNoteRepositoryIntegrationTests {
......
......@@ -23,7 +23,6 @@ import sample.jpa.domain.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
......@@ -36,7 +35,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
@Transactional
public class JpaTagRepositoryIntegrationTests {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment