Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- public class Producto {
- private Integer id;
- private String nombre;
- private List<Formato> listaFormatos;
- public Producto() {
- }
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getNombre() {
- return nombre;
- }
- public void setNombre(String nombre) {
- this.nombre = nombre;
- }
- @OneToMany(mappedBy = "producto", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
- public List<Formato> getListaFormatos() {
- return listaFormatos;
- }
- public void setListaFormatos(List<Formato> listaFormatos) {
- this.listaFormatos = listaFormatos;
- }
- }
- @Entity
- public class Formato {
- private Integer id;
- private Integer cantidad;
- private String unidadMedida;
- private Producto producto;
- public Formato() {
- }
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- @ManyToOne
- @JoinColumn(name = "producto_id", referencedColumnName = "id")
- public Producto getProducto() {
- return producto;
- }
- public void setProducto(Producto producto) {
- this.producto = producto;
- }
- public Integer getCantidad() {
- return cantidad;
- }
- public void setCantidad(Integer cantidad) {
- this.cantidad = cantidad;
- }
- public String getUnidadMedida() {
- return unidadMedida;
- }
- public void setUnidadMedida(String unidadMedida) {
- this.unidadMedida = unidadMedida;
- }
- }
- public interface ProductoRepository extends CrudRepository<Producto, Integer> {
- }
- spring.datasource.url = jdbc:mysql://localhost:3306/x1
- spring.datasource.username = x2
- spring.datasource.password = x3
- spring.jpa.show-sql=true
- spring.jpa.database=mysql
- spring.jpa.hibernate.ddl-auto=create-drop
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-jpa</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-rest</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-jersey</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-mail</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <optional>true</optional>
- </dependency>
- </dependencies>
- {"nombre": "x",
- "listaFormatos": [
- {"cantidad": 1,
- "unidadMedida":"kg"},
- {"cantidad": 2,
- "unidadMedida":"g"}
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement