the [com.maciejwalkowiak.springio.ordersjpa.Order] entity is unidirectional and does not render very efficient SQL statements. Consider using a bidirectional one-to-many association instead. For more info about this event, check out this User Guide link - https:// vladmihalcea.com/hypersistence-optimizer/docs/user-guide/#UnidirectionalOneToManyEvent CRITICAL - EagerFetchingEvent - The [product] attribute in the [com.maciejwalkowiak.springio.ordersjpa.OrderItem] entity uses eager fetching. Consider using a lazy fetching which, not only that is more efficient, but it is way more flexible when it comes to fetching data. For more info about this event, check out this User Guide link - https://vladmihalcea.com/hypersistence-optimizer/docs/user-guide/#EagerFetchingEvent MAJOR - SkipAutoCommitCheckEvent - You should set the [hibernate.connection.provider_disables_autocommit] configuration property to [true] while also making sure that the underlying DataSource is configured to disable the auto-commit flag whenever a new Connection is being acquired. For more info about this event, check out this User Guide link - https://vladmihalcea.com/hypersistence-optimizer/docs/user-guide/ #SkipAutoCommitCheckEvent
private Long id; @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "order_id") private Set<OrderItem> items; } @Entity class OrderItem { @Id @GeneratedValue private Long id; private int quantity; @ManyToOne private Product product; } @Entity class Product { @Id @GeneratedValue private Long id; private String name; • which entity should have corresponding repository? • should OrderItem have a reference to product?
private Long id; @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "order_id") private Set<OrderItem> items; } @Entity class OrderItem { @Id @GeneratedValue private Long id; private int quantity; @ManyToOne private Product product; } @Entity class Product { @Id @GeneratedValue private Long id; private String name; • which entity should have corresponding repository? • should OrderItem have a reference to product? • should OrderItem have a reference to Order?
private Long id; @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "order_id") private Set<OrderItem> items; } @Entity class OrderItem { @Id @GeneratedValue private Long id; private int quantity; @ManyToOne private Product product; } @Entity class Product { @Id @GeneratedValue private Long id; private String name; • which entity should have corresponding repository? • should OrderItem have a reference to product? • should OrderItem have a reference to Order?
as order_id4_0_0_, items0_.id as id1_0_0_, items0_.id as id1_0_1_, items0_.product_id as product_3_0_1_, items0_.quantity as quantity2_0_1_, product1_.id as id1_2_2_, product1_.name as name2_2_2_ from order_item items0_ left outer join product product1_ on items0_.product_id=product1_.id where items0_.order_id=? select items0_.order_id as order_id4_0_0_, items0_.id as id1_0_0_, items0_.id as id1_0_1_, items0_.product_id as product_3_0_1_, items0_.quantity as quantity2_0_1_, product1_.id as id1_2_2_, product1_.name as name2_2_2_ from order_item items0_ left outer join product product1_ on items0_.product_id=product1_.id where items0_.order_id=? select items0_.order_id as order_id4_0_0_, items0_.id as id1_0_0_, items0_.id as id1_0_1_, items0_.product_id as product_3_0_1_, items0_.quantity as quantity2_0_1_, product1_.id as id1_2_2_, product1_.name as name2_2_2_ from order_item items0_ left outer join product product1_ on items0_.product_id=product1_.id where items0_.order_id=?
as order_id4_0_0_, items0_.id as id1_0_0_, items0_.id as id1_0_1_, items0_.product_id as product_3_0_1_, items0_.quantity as quantity2_0_1_, product1_.id as id1_2_2_, product1_.name as name2_2_2_ from order_item items0_ left outer join product product1_ on items0_.product_id=product1_.id where items0_.order_id=? select items0_.order_id as order_id4_0_0_, items0_.id as id1_0_0_, items0_.id as id1_0_1_, items0_.product_id as product_3_0_1_, items0_.quantity as quantity2_0_1_, product1_.id as id1_2_2_, product1_.name as name2_2_2_ from order_item items0_ left outer join product product1_ on items0_.product_id=product1_.id where items0_.order_id=? select items0_.order_id as order_id4_0_0_, items0_.id as id1_0_0_, items0_.id as id1_0_1_, items0_.product_id as product_3_0_1_, items0_.quantity as quantity2_0_1_, product1_.id as id1_2_2_, product1_.name as name2_2_2_ from order_item items0_ left outer join product product1_ on items0_.product_id=product1_.id where items0_.order_id=? select order_id, sum(quantity) from order_item group by order_id;
- Spring Tips: JOOQ • https:/ /www.youtube.com/watch?v=4pwTd6NEuN0 - Database centric applications with Spring Boot and jOOQ - Michael Simons • https:/ /start.spring.io/ - and select JOOQ starter