BAEL-1319 Quick Guide on Data.sql and Schema.sql Files in Spring
This commit is contained in:
parent
7b4d644d1e
commit
4857675e2d
33
spring-jpa/src/main/java/org/baeldung/sqlfiles/Country.java
Normal file
33
spring-jpa/src/main/java/org/baeldung/sqlfiles/Country.java
Normal file
@ -0,0 +1,33 @@
|
||||
package org.baeldung.sqlfiles;
|
||||
|
||||
import static javax.persistence.GenerationType.IDENTITY;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Country {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
5
spring-jpa/src/main/resources/data.sql
Normal file
5
spring-jpa/src/main/resources/data.sql
Normal file
@ -0,0 +1,5 @@
|
||||
INSERT INTO country (name) VALUES ('India');
|
||||
INSERT INTO country (name) VALUES ('Brazil');
|
||||
INSERT INTO country (name) VALUES ('USA');
|
||||
INSERT INTO country (name) VALUES ('Italy');
|
||||
COMMIT;
|
5
spring-jpa/src/main/resources/schema.sql
Normal file
5
spring-jpa/src/main/resources/schema.sql
Normal file
@ -0,0 +1,5 @@
|
||||
CREATE TABLE country (
|
||||
id INTEGER NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
1
spring-jpa/src/main/resources/sqlfiles.properties
Normal file
1
spring-jpa/src/main/resources/sqlfiles.properties
Normal file
@ -0,0 +1 @@
|
||||
spring.jpa.hibernate.ddl-auto=none
|
Loading…
x
Reference in New Issue
Block a user