= …; // ୈ1ҾʹΤϯςΟςΟΫϥεɺୈ2ҾʹओΩʔ Product product = em.find(Product.class, 1); ▸ جຊతʹશϑΟʔϧυʹ૬͢Δྻ͕ݕࡧ͞ΕΔ select product0_.id as id1_5_0_, product0_.category_id as category4_5_0_, product0_.name as name2_5_0_, product0_.price as price3_5_0_, product0_.vendor_id as vendor_i5_5_0_ from product product0_ where product0_.id=? ͜ΜͳSQL͕ ൃߦ͞ΕΔ
from product product0_ where product0_.id=? binding parameter [1] as [INTEGER] - [30] delete from product where id=? binding parameter [1] as [INTEGER] - [30]
= em.createQuery( "SELECT p FROM Product p WHERE p.id = :id", Product.class); query.setParameter("id", 1); Product product = query.getSingleResult(); TypedQuery<Product> query = em.createQuery( "SELECT p FROM Product p WHERE p.id <= :maxId" + " ORDER BY p.id", Product.class); query.setParameter("maxId", 5); List<Product> list = query.getResultList(); ▸ ୯Ұݕࡧ ▸ ෳݕࡧ
as id1_5_, product0_.category_id as category4_5_, product0_.name as name2_5_, product0_.price as price3_5_, product0_.vendor_id as vendor_i5_5_ from product product0_ where product0_.id=? ▸ ͲΜͳ42-͕ൃߦ͞ΕΔ͔+1"༷Ͱະఆٛ ʹશʹ࣮ґଘʢԼه)JCFSOBUFͷྫʣ
from product product0_ where product0_.id=? select (ྻলུ) from vendor vendor0_ where vendor0_.id=? @Entity public class Product { @ManyToOne(fetch = FetchType.LAZY) private Vendor vendor; } Product p = em.find(Product.class, 1); Vendor v = p.getVendor(); String n = v.getName() // ͜͜ͰSELECT 2ճ SELECT
order_summaryͷSELECT͕ൃߦ͞ΕΔʢ1ճʣ List<OrderSummary> list = em.createQuery( "SELECT os FROM OrderSummary os",OrderSummary.class) .getResultList(); for (OrderSummary os : list) { // ·ͩorder_detailಡΈࠐ·Ε͍ͯͳ͍ System.out.println(os); for (OrderDetail od : os.getOrderDetailList()) { // ͜͜Ͱorder_detailͷSELECT͕ൃߦ͞ΕΔ(Nճ) System.out.println(od); } }
List<OrderSummary> list = em.createQuery( "SELECT os FROM OrderSummary os" + " JOIN os.orderDetailList", OrderSummary.class) .getResultList(); for (OrderSummary os : list) { // ·ͩorder_detailಡΈࠐ·Ε͍ͯͳ͍ System.out.println(os); for (OrderDetail od : os.getOrderDetailList()) { // ͜͜Ͱorder_detailͷSELECT͕ൃߦ͞ΕΔ(Nճ) System.out.println(od); } }
as id1_3_, ordersumma0_.customer_id as customer3_3_, ordersumma0_.order_timestamp as order_ti2_3_ from order_summary ordersumma0_ inner join order_detail orderdetai1_ on ordersumma0_.id=orderdetai1_.summary_id where ordersumma0_.id=? JOINͯ͠Δ͚Ͳ order_summaryͷྻ ͔͠औಘͯ͠ͳ͍
as id1_3_0_, orderdetai1_.id as id1_2_1_, ordersumma0_.customer_id as customer3_3_0_, ordersumma0_.order_timestamp as order_ti2_3_0_, orderdetai1_.amount as amount2_2_1_, orderdetai1_.product_id as product_3_2_1_, orderdetai1_.summary_id as summary_4_2_0__, orderdetai1_.id as id1_2_0__ from order_summary ordersumma0_ inner join order_detail orderdetai1_ on ordersumma0_.id=orderdetai1_.summary_id where ordersumma0_.id=? JOINͯ͠ શྻऔಘ
distinct ordersumma0_.id as id1_3_0_, orderdetai1_.id as id1_2_1_, ordersumma0_.customer_id as customer3_3_0_, ordersumma0_.order_timestamp as order_ti2_3_0_, orderdetai1_.amount as amount2_2_1_, orderdetai1_.product_id as product_3_2_1_, orderdetai1_.summary_id as summary_4_2_0__, orderdetai1_.id as id1_2_0__ from order_summary ordersumma0_ inner join order_detail orderdetai1_ on ordersumma0_.id=orderdetai1_.summary_id where ordersumma0_.id=? distinct͕͕͘ SQLͷ݁Ռ ͜ͷ߹ಉ͡
as id1_3_0_, orderdetai1_.id as id1_2_1_, product2_.id as id1_4_2_, ordersumma0_.customer_id as customer3_3_0_, ordersumma0_.order_timestamp as order_ti2_3_0_, orderdetai1_.amount as amount2_2_1_, orderdetai1_.product_id as product_3_2_1_, orderdetai1_.summary_id as summary_4_2_0__, orderdetai1_.id as id1_2_0__, product2_.category_id as category4_4_2_, product2_.name as name2_4_2_, product2_.price as price3_4_2_, product2_.vendor_id as vendor_i5_4_2_ from order_summary ordersumma0_ inner join order_detail orderdetai1_ on ordersumma0_.id=orderdetai1_.summary_id inner join product product2_ on orderdetai1_.product_id=product2_.id where ordersumma0_.id=? 3ͭͷදΛ JOINͯ͠ શྻऔಘ
as id1_4_, product0_.category_id as category4_4_, product0_.name as name2_4_, product0_.price as price3_4_, product0_.vendor_id as vendor_i5_4_ from product product0_ where product0_.name like ? binding parameter [1] as [VARCHAR] - [%ύϚ%]
= "myAuditorAware") public class SpringDataJpaDaitokaiApplication { … } @Component public class MyAuditorAware implements AuditorAware<String> { @Override public String getCurrentAuditor() {return "user01";} } Spring Security͔Β Ϣʔβʔ໊Λऔಘͯ͠OK