I am trying to learn SpringBoot and trying to make an API.
I have multiple entities as follows:
@Entity
public class Superhero {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
}
And then another Entity is Superhero_stats - where I want to add additional fields and map it with heroId from SuperHero Entity.
@Entity
@Table(name = "superhero_stats")
public class SuperheroStats {
@Id
@GeneratedValue
private int stats_id;
@OneToOne(mappedBy = "superhero", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
Superhero superhero;
private int intelligence;
}
My question is how to write the sql queries in data.sql script in resources. I have found many examples which are trying to do the same thing in main Application class, but I also want to know if this is possible through data.sql file.
Here is the sample data.sql that I am trying
insert into superhero(name) values ('Spiderman')
insert into superhero(name) values ('Superman')
insert into superhero(name) values ('Batman')
insert into superhero_stats(stats_id, superhero, intelligence) values (1,1,100)
insert into superhero_stats(stats_id, superhero, intelligence) values (2,2,200)
insert into superhero_stats(stats_id, superhero, intelligence) values (3,3,300)
Edit : I am trying this at start of my application. NOT for testing.