SlideShare a Scribd company logo
1 of 118
Download to read offline
(C) CASAREAL, Inc. All rights reserved.
1
(C) CASAREAL, Inc. All rights reserved.
2
(C) CASAREAL, Inc. All rights reserved.
3
(C) CASAREAL, Inc. All rights reserved.
▸
▸ 😅
▸
▸
4
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
5
(C) CASAREAL, Inc. All rights reserved.
▸
6
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
▸
7
(C) CASAREAL, Inc. All rights reserved.
8
Spring Web 4 Spring MVC
Spring Boot
Developer
2 Spring Boot
Spring Cloud
Services
3
Spring Cloud Microservices
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
9
(C) CASAREAL, Inc. All rights reserved.
10
(C) CASAREAL, Inc. All rights reserved.
11
(C) CASAREAL, Inc. All rights reserved.
▸
12
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
13
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
14
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
15
※ JPA 2.1(Java EE 7) 

(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
16
(C) CASAREAL, Inc. All rights reserved.
▸
17
<dependency>	
				<groupId>org.springframework.boot</groupId>	
				<artifactId>spring-boot-starter-data-jpa</artifactId>	
</dependency>
(C) CASAREAL, Inc. All rights reserved.
▸
18
<dependency>	
				<groupId>org.springframework.data</groupId>	
				<artifactId>spring-data-jpa</artifactId>	
				<version>2.0.1.RELEASE</version>	
</dependency>	
<dependency>	
				<groupId>org.hibernate</groupId>	
				<artifactId>hibernate-entitymanager</artifactId>	
				<version>5.2.12.Final</version>	
</dependency>
(C) CASAREAL, Inc. All rights reserved.
▸
19
logging.level.org.hibernate.SQL=debug	
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=	
trace
<logger	name="org.hibernate.SQL"	level="DEBUG"	/>	
<logger	name="org.hibernate.type.descriptor.sql.BasicBinder"	
			level="TRACE"	/>
▸
▸
※hibernate.show_sql=true
(C) CASAREAL, Inc. All rights reserved.
▸
20
spring.jpa.properties.hibernate.format_sql=true
▸
▸
▸
(C) CASAREAL, Inc. All rights reserved.
21
(C) CASAREAL, Inc. All rights reserved.
22


DB
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
23
@Entity	
public	class	Product	{	
		@Id	
		private	Integer	id;	
		private	String	name;		
		//	setter/getter	
}
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸ 

24
(C) CASAREAL, Inc. All rights reserved.
▸
▸ 

25
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸ 

26
(C) CASAREAL, Inc. All rights reserved.
27
NEW new
MANAGED
DETACHED
REMOVED
(C) CASAREAL, Inc. All rights reserved.
28
find()
persist() 1
remove() 1
merge()
detach()
flush() DB
clear()
refresh() DB
(C) CASAREAL, Inc. All rights reserved.
29
persist()
detach()

clear()
merge()
remove()
flush()
flush()
refresh()
find()

JPQL
detach()

clear()
(C) CASAREAL, Inc. All rights reserved.
30
EntityManager	em	=	…;	
//	 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 

(C) CASAREAL, Inc. All rights reserved.
31
Product	product	=	new	Product(“ ”,	100000L);	
em.persist(product);
▸
▸
insert		
into	
				product	
				(category_id,	name,	price,	vendor_id,	id)		
values	
				(?,	?,	?,	?,	?)
(C) CASAREAL, Inc. All rights reserved.
32
//	find() MANAGED 	
Product	product	=	em.find(Product.class,	1);	
//	 	
product.setName(" ");	
//	 ( OK)	
em.flush();
▸
(C) CASAREAL, Inc. All rights reserved.
33
select	…	from	product	product0_	where	product0_.id=?	
binding	parameter	[1]	as	[INTEGER]	-	[1]	
update	product		
set	category_id=?,	name=?,	price=?,	vendor_id=?		
where	id=?	
binding	parameter	[1]	as	[INTEGER]	-	[1]	
binding	parameter	[2]	as	[VARCHAR]	-	[ ]	
binding	parameter	[3]	as	[BIGINT]	-	[100000]	
binding	parameter	[4]	as	[INTEGER]	-	[1]	
binding	parameter	[5]	as	[INTEGER]	-	[1]
(C) CASAREAL, Inc. All rights reserved.
34
Product	product	=	new	Product();	
product.setId(1);	
product.setName(“ ");	
//	merge() 	
em.merge(product);	
em.flush();
▸
(C) CASAREAL, Inc. All rights reserved.
35
select	…	from	product	product0_	where	product0_.id=?	
binding	parameter	[1]	as	[INTEGER]	-	[1]	
update	product		
set	category_id=?,	name=?,	price=?,	vendor_id=?		
where	id=?	
binding	parameter	[1]	as	[INTEGER]	-	[null]	
binding	parameter	[2]	as	[VARCHAR]	-	[ ]	
binding	parameter	[3]	as	[BIGINT]	-	[null]	
binding	parameter	[4]	as	[INTEGER]	-	[null]	
binding	parameter	[5]	as	[INTEGER]	-	[1]
▸
(C) CASAREAL, Inc. All rights reserved.
▸
▸
36
Product	mergedProduct	=	em.merge(product);	
//	 MANAGED 	
assertTrue(em.contains(mergedProduct));	
//	 	
assertFalse(em.contains(product));
(C) CASAREAL, Inc. All rights reserved.
37
//	find() MANAGED 	
Product	product	=	em.find(Product.class,	30);	
//	REMOVED 	
em.remove(product);	
//	 ( OK)	
em.flush();
▸
(C) CASAREAL, Inc. All rights reserved.
38
select	…	from	product	product0_	where	product0_.id=?	
binding	parameter	[1]	as	[INTEGER]	-	[30]	
delete	from	product	where	id=?	
binding	parameter	[1]	as	[INTEGER]	-	[30]
(C) CASAREAL, Inc. All rights reserved.
39
//	find() MANAGED 	
Product	product	=	em.find(Product.class,	30);	
//	REMOVED 	
em.remove(product);	
//	DETACHED 	
em.detach(product);	
//	DETACHED DB 	
em.flush();
▸
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
40
(C) CASAREAL, Inc. All rights reserved.
41
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
42
(C) CASAREAL, Inc. All rights reserved.
43
TypedQuery<Product>	query	=	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();
▸
▸
(C) CASAREAL, Inc. All rights reserved.
44
select	
				product0_.id	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=?
▸ 

(C) CASAREAL, Inc. All rights reserved.
45
SELECT	 	FROM	 	[AS]	 	
WHERE	 . 	<=	:
▸
▸ 

▸
(C) CASAREAL, Inc. All rights reserved.
▸
▸
46
SELECT	new	com.example.demo.dto.CountDto(	
																				od.product.id,	COUNT(od))	
FROM	OrderDetail	od	GROUP	BY	od.product.id
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
47
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
48
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
49
(C) CASAREAL, Inc. All rights reserved.
▸
▸
50
(C) CASAREAL, Inc. All rights reserved.
51
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
52
@Entity	
public	class	Product	{	
		…	
		@ManyToOne	
		@JoinColumn(name="vendor_id")	
		private	Vendor	vendor;	
}
@Entity	
public	class	Vendor	{	
		…	
}
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
53
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
54
@Entity	
public	class	Product	{	
		…	
		@ManyToOne(fetch	=	FetchType.LAZY)	
		@JoinColumn(name="vendor_id")	
		private	Vendor	vendor;	
}
(C) CASAREAL, Inc. All rights reserved.
55
select	( )	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
(C) CASAREAL, Inc. All rights reserved.
▸
56
em.getTransaction().begin();	
Product	p	=	em.find(Product.class,	1);	
em.getTransaction().rollback();	
Vendor	v	=	p.getVendor();	
String	n	=	v.getName();	//
(C) CASAREAL, Inc. All rights reserved.
57
@Entity	public	class	Product	{	
		@ManyToOne(fetch	=	FetchType.EAGER)	
		private	Vendor	vendor;	
}	
Product	p	=	em.find(Product.class,	1);	
Vendor	v	=	p.getVendor();	//	
select	( )	from	product	product0_		
left	outer	join	vendor	vendor2_		
		on	product0_.vendor_id=vendor2_.id		
where	product0_.id=?
1
SELECT
(C) CASAREAL, Inc. All rights reserved.
▸
▸ 

▸
58
(C) CASAREAL, Inc. All rights reserved.
59
//	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);	
		}	
}
(C) CASAREAL, Inc. All rights reserved.
60
//	order_summary SELECT 1 	
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);	
		}	
}
(C) CASAREAL, Inc. All rights reserved.
61
select	
				ordersumma0_.id	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 

(C) CASAREAL, Inc. All rights reserved.
▸
62
//	order_summary SELECT 1 	
List<OrderSummary>	list	=	em.createQuery(	
				"SELECT	os	FROM	OrderSummary	os"	+		
				"	JOIN	FETCH	os.orderDetailList"	+		
				,	OrderSummary.class)	
		.getResultList();
(C) CASAREAL, Inc. All rights reserved.
63
select	
				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=?
JOIN 

(C) CASAREAL, Inc. All rights reserved.
64
OrderSummary{id=1,	orderTimestamp=2017-04-01T10:00}	
OrderDetail{id=1,	amount=2}	
OrderDetail{id=2,	amount=2}	
OrderDetail{id=3,	amount=2}	
OrderSummary{id=1,	orderTimestamp=2017-04-01T10:00}	
OrderDetail{id=1,	amount=2}	
OrderDetail{id=2,	amount=2}	
OrderDetail{id=3,	amount=2}	
OrderSummary{id=1,	orderTimestamp=2017-04-01T10:00}	
OrderDetail{id=1,	amount=2}	
OrderDetail{id=2,	amount=2}	
OrderDetail{id=3,	amount=2}	
OrderSummary{id=2,	orderTimestamp=2017-04-01T10:00}	
OrderDetail{id=4,	amount=2}	
OrderDetail{id=5,	amount=2}	


(C) CASAREAL, Inc. All rights reserved.
65
//	order_summary SELECT 1 	
List<OrderSummary>	list	=	em.createQuery(	
				"SELECT	DISTINCT	os	FROM	OrderSummary	os"	+		
				"	JOIN	FETCH	os.orderDetailList"	+		
				,	OrderSummary.class)	
		.getResultList();
(C) CASAREAL, Inc. All rights reserved.
66
select	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 

(C) CASAREAL, Inc. All rights reserved.
67
OrderSummary{id=1,	orderTimestamp=2017-04-01T10:00}	
OrderDetail{id=3,	amount=2}	
OrderDetail{id=1,	amount=2}	
OrderDetail{id=2,	amount=2}	
OrderSummary{id=2,	orderTimestamp=2017-04-01T10:00}	
OrderDetail{id=5,	amount=2}	
OrderDetail{id=6,	amount=2}	
OrderDetail{id=4,	amount=2}	
OrderSummary{id=9,	orderTimestamp=2017-04-01T10:00}	
OrderSummary{id=7,	orderTimestamp=2017-04-01T10:00}	
OrderSummary{id=6,	orderTimestamp=2017-04-01T10:00}	
OrderSummary{id=5,	orderTimestamp=2017-04-01T10:00}	
OrderSummary{id=4,	orderTimestamp=2017-04-01T10:00}	
OrderSummary{id=3,	orderTimestamp=2017-04-01T10:00}	
OrderSummary{id=8,	orderTimestamp=2017-04-01T10:00}	
OrderSummary{id=10,	orderTimestamp=2017-04-01T10:00}


(C) CASAREAL, Inc. All rights reserved.
▸
68
(C) CASAREAL, Inc. All rights reserved.
//	order_summary order_detail product JOIN 	
OrderSummary	orderSummary	=	em.createQuery(	
				"SELECT	os	FROM	OrderSummary	os"	+		
				"	JOIN	FETCH	os.orderDetailList	od"	+		
				"	JOIN	FETCH	od.product	p"	+		
				"	WHERE	os.id	=	:id",	OrderSummary.class)	
		.setParameter("id",	1)	
		.getSingleResult();
▸
69
(C) CASAREAL, Inc. All rights reserved.
70
select	
				ordersumma0_.id	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 

(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
71
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸ 

▸
▸
72
https://www.casareal.co.jp/recruit/jobs/
ls_teacher.php
(C) CASAREAL, Inc. All rights reserved.
▸ 

✕ 

✕
▸ 







73
https://www.casareal.co.jp/ls/service/shinjinseminar/course01
(C) CASAREAL, Inc. All rights reserved.
74
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
75
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
76
Query	query	=	em.createNativeQuery(	
		"select	id,	name,	price,	vendor_id"		
		+	"	from	product	where	id	=	:id",	Product.class);	
query.setParameter("id",	1);	
Product	product	=	(Product)	query.getSingleResult();
(C) CASAREAL, Inc. All rights reserved.
▸
77
Query	query	=	em.createNativeQuery(	
		"select	id,	name	from	product	where	id	=	:id");	
query.setParameter("id",	1);	
//	0 id 1 name	
Object[]	objs	=	(Object[])	query.getSingleResult();	
Integer	productId	=	(Integer)	objs[0];	
String	productName	=	(String)	objs[1];
(C) CASAREAL, Inc. All rights reserved.
▸
▸
78
(C) CASAREAL, Inc. All rights reserved.
79
@Entity	
@SqlResultSetMapping(	
		name	=	"product_id_name",	//	 	
		classes	=	{	
				@ConstructorResult(targetClass	=	ProductDto.class,	
						columns	=	{	
								@ColumnResult(name	=	"id"),	
								@ColumnResult(name	=	"name")	
						}	
				)	
		}	
)	
public	class	Product	{	…	}


※@SqlResultSetMappings @SqlResultSetMapping
(C) CASAREAL, Inc. All rights reserved.
80
Query	query	=	em.createNativeQuery(	
		"select	id,	name	from	product	where	id	=	:id",		
		"product_id_name");	//	@SqlResultSetMapping name 	
query.setParameter("id",	1);	
ProductDto	productDto	=		
		(ProductDto)	query.getSingleResult();
public	class	ProductDto	{	
		private	Integer	id;	
		private	String	name;	
		public	ProductDto(Integer	id,	String	name)	{	…	}	
}


(C) CASAREAL, Inc. All rights reserved.
▸
81
//	H2	Database LEFT 	
TypedQuery<Product>	query	=	em.createQuery(	
		"SELECT	p	FROM	Product	p"		
				+	"	WHERE	FUNCTION('LEFT',	p.name,	2)	=	' '",	
		Product.class);	
List<Product>	productList	=	query.getResultList();
(C) CASAREAL, Inc. All rights reserved.
▸
82
StoredProcedureQuery	query	=		
		em.createStoredProcedureQuery(" ",	
				 .class);	
query.setParameter(" ",	 );	
List< >	list	=		
		(List< >)	query.getResultList();
※
(C) CASAREAL, Inc. All rights reserved.
▸
83
@Entity	
@Index(members	=	{"name"})	
public	class	Product	{	
		…	
}
※ 

※@Indices @Index
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
84
(C) CASAREAL, Inc. All rights reserved.
▸
▸
85
(C) CASAREAL, Inc. All rights reserved.
86
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
87
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
88
(C) CASAREAL, Inc. All rights reserved.
▸
89
public	interface	ProductRepository	
				extends	JpaRepository<Product,	Integer>	{	
		//	 OK	
}
※@Repository
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
90
(C) CASAREAL, Inc. All rights reserved.
91
@Service	
public	class	ProductService	{	
		private	final	ProductRepository	repo;	
			
		@Autowired	//	 DI 	
		public	ProductService(ProductRepository	repo)	{	
				this.repo	=	repo;	
		}	
			
		@Transactional	
		public	void	insert(Product	product)	{	
				repo.save(product);	
		}	
}
※@Autowired Spring 4.3 

1
(C) CASAREAL, Inc. All rights reserved.
▸
▸
92
public	interface	ProductRepository	
				extends	JpaRepository<Product,	Integer>	{	
		@Query("SELECT	p	FROM	Product	p	JOIN	FETCH	p.vendor"	
						+	"	WHERE	p.id	=	:id")	
		Product	findByIdJoinFetch(@Param("id")	Integer	id);	
}
(C) CASAREAL, Inc. All rights reserved.
▸
93
public	interface	ProductRepository	
				extends	JpaRepository<Product,	Integer>	{	
		@Modifying	
		@Query("UPDATE	Product	p	SET	p.name	=	:name"	
									+	"	WHERE	p.id	=	:id")	
		void	updateName(@Param("name")	String	name,	
																		@Param("id")	Integer	id);	
}
(C) CASAREAL, Inc. All rights reserved.
▸
94
public	interface	ProductRepository	
				extends	JpaRepository<Product,	Integer>	{	
		@Lock(LockModeType.PESSIMISTIC_READ)	
		@Query("SELECT	p	FROM	Product	p	JOIN	FETCH	p.vendor"	
						+	"	WHERE	p.id	=	:id")	
		Product	findByIdJoinFetch(@Param("id")	Integer	id);	
}
※ 

https://www.slideshare.net/masatoshitada7/jpa20140518-ccc-r15-jjug-ccc
(C) CASAREAL, Inc. All rights reserved.
▸
95
public	interface	ProductRepository	
				extends	JpaRepository<Product,	Integer>	{	
		@EntityGraph(" ")	
		@Query("SELECT	p	FROM	Product	p	JOIN	FETCH	p.vendor"	
						+	"	WHERE	p.id	=	:id")	
		Product	findByIdJoinFetch(@Param("id")	Integer	id);	
}
※ 

https://blog.ik.am/entries/350
(C) CASAREAL, Inc. All rights reserved.
▸
96
public	interface	ProductRepository	
				extends	JpaRepository<Product,	Integer>	{	
		//	name 	
		List<Product>	findByNameContaining(String	keyword);	
}
(C) CASAREAL, Inc. All rights reserved.
97
select	
				product0_.id	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]	-	[% %]
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
98
(C) CASAREAL, Inc. All rights reserved.
▸
▸
99


(C) CASAREAL, Inc. All rights reserved.
▸
100
@Entity	public	class	Hoge	{	
		@CreatedBy	String	createdUser;	
		@CreatedDate	LocalDateTime	createdDate;	
		@LastModifiedBy	String	modifiedUser;	
		@LastModifiedDate	LocalDateTime	lastModifiedDate;	
}
(C) CASAREAL, Inc. All rights reserved.
101
@SpringBootApplication	
@EnableJpaAuditing(auditorAwareRef	=	"myAuditorAware")	
public	class	SpringDataJpaDaitokaiApplication	{	…	}
@Component	
public	class	MyAuditorAware	
				implements	AuditorAware<String>	{	
		@Override	
		public	Optional<String>	getCurrentAuditor()	{	
				return	Optional.of("user01");}	
}
Spring Security 

OK
(C) CASAREAL, Inc. All rights reserved.
102
<entity-mappings>	
		<persistence-unit-metadata>	
				<persistence-unit-defaults>	
						<entity-listeners>	
								<entity-listener	
class="org.springframework.data.jpa.domain.support.AuditingEntityListene
r"	/>	
					</entity-listeners>	
				</persistence-unit-defaults>	
		</persistence-unit-metadata>	
</entity-mappings>
▸
▸
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
103
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
104
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
▸
105
(C) CASAREAL, Inc. All rights reserved.
106
(C) CASAREAL, Inc. All rights reserved.
▸
107
http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/reference/htmlsingle/#boot-features-jpa-in-
web-environment
(C) CASAREAL, Inc. All rights reserved.
▸
108
spring.jpa.open-in-view=false
(C) CASAREAL, Inc. All rights reserved.
▸
▸
109
@Entity	public	class	Hoge	{	
		//	Spring	Boot @Column 	
		@Column(name=“foo_bar”)	String	fooBar;	
}
http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/reference/htmlsingle/#howto-configure-
hibernate-naming-strategy
(C) CASAREAL, Inc. All rights reserved.
▸
110
spring.jpa.hibernate.naming.physical-strategy=Strategy FQCN	
spring.jpa.hibernate.naming.implicit-strategy=Strategy FQCN
(C) CASAREAL, Inc. All rights reserved.
▸
▸
111
@SpringBootApplication	
@EntityScan(basePackages	=	{	
		"com.example.demo.persistence.entity",	
		"org.springframework.data.jpa.convert.threeten"})	
public	class	SpringDataJpaDaitokaiApplication	{	…	}
http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/reference/htmlsingle/#howto-separate-entity-
definitions-from-spring-configuration
(C) CASAREAL, Inc. All rights reserved.
112
(C) CASAREAL, Inc. All rights reserved.
▸
113
(C) CASAREAL, Inc. All rights reserved.




114
😅
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
▸
115
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
▸
▸
▸
116
(C) CASAREAL, Inc. All rights reserved.
▸
▸
▸
▸
▸
▸
▸
▸
117
(C) CASAREAL, Inc. All rights reserved.
▸
118

More Related Content

What's hot

これからSpringを使う開発者が知っておくべきこと
これからSpringを使う開発者が知っておくべきことこれからSpringを使う開発者が知っておくべきこと
これからSpringを使う開発者が知っておくべきこと土岐 孝平
 
マルチテナントのアプリケーション実装〜実践編〜
マルチテナントのアプリケーション実装〜実践編〜マルチテナントのアプリケーション実装〜実践編〜
マルチテナントのアプリケーション実装〜実践編〜Yoshiki Nakagawa
 
Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編Masahito Zembutsu
 
雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニングyoku0825
 
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetupこれで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線MeetupMasatoshi Tada
 
ドメインオブジェクトの見つけ方・作り方・育て方
ドメインオブジェクトの見つけ方・作り方・育て方ドメインオブジェクトの見つけ方・作り方・育て方
ドメインオブジェクトの見つけ方・作り方・育て方増田 亨
 
Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門Ryosuke Uchitate
 
Where狙いのキー、order by狙いのキー
Where狙いのキー、order by狙いのキーWhere狙いのキー、order by狙いのキー
Where狙いのキー、order by狙いのキーyoku0825
 
さくっと理解するSpring bootの仕組み
さくっと理解するSpring bootの仕組みさくっと理解するSpring bootの仕組み
さくっと理解するSpring bootの仕組みTakeshi Ogawa
 
世界一わかりやすいClean Architecture
世界一わかりやすいClean Architecture世界一わかりやすいClean Architecture
世界一わかりやすいClean ArchitectureAtsushi Nakamura
 
マルチテナント化で知っておきたいデータベースのこと
マルチテナント化で知っておきたいデータベースのことマルチテナント化で知っておきたいデータベースのこと
マルチテナント化で知っておきたいデータベースのことAmazon Web Services Japan
 
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Ryosuke Uchitate
 
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)Takuto Wada
 
ドメイン駆動設計のためのオブジェクト指向入門
ドメイン駆動設計のためのオブジェクト指向入門ドメイン駆動設計のためのオブジェクト指向入門
ドメイン駆動設計のためのオブジェクト指向入門増田 亨
 
はまる!JPA(初学者向けライト版)
はまる!JPA(初学者向けライト版)はまる!JPA(初学者向けライト版)
はまる!JPA(初学者向けライト版)Masatoshi Tada
 
ドメイン駆動設計 の 実践 Part3 DDD
ドメイン駆動設計 の 実践 Part3 DDDドメイン駆動設計 の 実践 Part3 DDD
ドメイン駆動設計 の 実践 Part3 DDD増田 亨
 
SQL大量発行処理をいかにして高速化するか
SQL大量発行処理をいかにして高速化するかSQL大量発行処理をいかにして高速化するか
SQL大量発行処理をいかにして高速化するかShogo Wakayama
 
Dockerfileを改善するためのBest Practice 2019年版
Dockerfileを改善するためのBest Practice 2019年版Dockerfileを改善するためのBest Practice 2019年版
Dockerfileを改善するためのBest Practice 2019年版Masahito Zembutsu
 

What's hot (20)

これからSpringを使う開発者が知っておくべきこと
これからSpringを使う開発者が知っておくべきことこれからSpringを使う開発者が知っておくべきこと
これからSpringを使う開発者が知っておくべきこと
 
マルチテナントのアプリケーション実装〜実践編〜
マルチテナントのアプリケーション実装〜実践編〜マルチテナントのアプリケーション実装〜実践編〜
マルチテナントのアプリケーション実装〜実践編〜
 
Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編
 
Mavenの真実とウソ
Mavenの真実とウソMavenの真実とウソ
Mavenの真実とウソ
 
雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング
 
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetupこれで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
 
ドメインオブジェクトの見つけ方・作り方・育て方
ドメインオブジェクトの見つけ方・作り方・育て方ドメインオブジェクトの見つけ方・作り方・育て方
ドメインオブジェクトの見つけ方・作り方・育て方
 
Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門
 
Where狙いのキー、order by狙いのキー
Where狙いのキー、order by狙いのキーWhere狙いのキー、order by狙いのキー
Where狙いのキー、order by狙いのキー
 
さくっと理解するSpring bootの仕組み
さくっと理解するSpring bootの仕組みさくっと理解するSpring bootの仕組み
さくっと理解するSpring bootの仕組み
 
世界一わかりやすいClean Architecture
世界一わかりやすいClean Architecture世界一わかりやすいClean Architecture
世界一わかりやすいClean Architecture
 
マルチテナント化で知っておきたいデータベースのこと
マルチテナント化で知っておきたいデータベースのことマルチテナント化で知っておきたいデータベースのこと
マルチテナント化で知っておきたいデータベースのこと
 
分散トレーシング技術について(Open tracingやjaeger)
分散トレーシング技術について(Open tracingやjaeger)分散トレーシング技術について(Open tracingやjaeger)
分散トレーシング技術について(Open tracingやjaeger)
 
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
 
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
 
ドメイン駆動設計のためのオブジェクト指向入門
ドメイン駆動設計のためのオブジェクト指向入門ドメイン駆動設計のためのオブジェクト指向入門
ドメイン駆動設計のためのオブジェクト指向入門
 
はまる!JPA(初学者向けライト版)
はまる!JPA(初学者向けライト版)はまる!JPA(初学者向けライト版)
はまる!JPA(初学者向けライト版)
 
ドメイン駆動設計 の 実践 Part3 DDD
ドメイン駆動設計 の 実践 Part3 DDDドメイン駆動設計 の 実践 Part3 DDD
ドメイン駆動設計 の 実践 Part3 DDD
 
SQL大量発行処理をいかにして高速化するか
SQL大量発行処理をいかにして高速化するかSQL大量発行処理をいかにして高速化するか
SQL大量発行処理をいかにして高速化するか
 
Dockerfileを改善するためのBest Practice 2019年版
Dockerfileを改善するためのBest Practice 2019年版Dockerfileを改善するためのBest Practice 2019年版
Dockerfileを改善するためのBest Practice 2019年版
 

Similar to Spring Data JPAによるデータアクセス徹底入門 #jsug

ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説Masatoshi Tada
 
Spring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjugSpring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjugMasatoshi Tada
 
Java EE 8新機能解説 -Bean Validation 2.0編-
Java EE 8新機能解説 -Bean Validation 2.0編-Java EE 8新機能解説 -Bean Validation 2.0編-
Java EE 8新機能解説 -Bean Validation 2.0編-Masatoshi Tada
 
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~Masatoshi Tada
 
保守・追加開発に必要な「Springの正しい知識」とは?20171109
保守・追加開発に必要な「Springの正しい知識」とは?20171109保守・追加開発に必要な「Springの正しい知識」とは?20171109
保守・追加開発に必要な「Springの正しい知識」とは?20171109CASAREAL, Inc.
 
JSUG SpringOne 2017報告会
JSUG SpringOne 2017報告会JSUG SpringOne 2017報告会
JSUG SpringOne 2017報告会Masatoshi Tada
 
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerConnor McDonald
 
How Zocdoc Achieves Automatic Threat Detection & Remediation with Security as...
How Zocdoc Achieves Automatic Threat Detection & Remediation with Security as...How Zocdoc Achieves Automatic Threat Detection & Remediation with Security as...
How Zocdoc Achieves Automatic Threat Detection & Remediation with Security as...Amazon Web Services
 
BREWBEANS.sql.txtDROP TABLE BB_Department CASCADE CONSTRAINTS .docx
BREWBEANS.sql.txtDROP TABLE BB_Department CASCADE CONSTRAINTS .docxBREWBEANS.sql.txtDROP TABLE BB_Department CASCADE CONSTRAINTS .docx
BREWBEANS.sql.txtDROP TABLE BB_Department CASCADE CONSTRAINTS .docxhartrobert670
 
Real-time Data Updates for Neo4j Using GraphQL Subscriptions
Real-time Data Updates for Neo4j Using GraphQL SubscriptionsReal-time Data Updates for Neo4j Using GraphQL Subscriptions
Real-time Data Updates for Neo4j Using GraphQL SubscriptionsNeo4j
 
Altinity Quickstart for ClickHouse-2202-09-15.pdf
Altinity Quickstart for ClickHouse-2202-09-15.pdfAltinity Quickstart for ClickHouse-2202-09-15.pdf
Altinity Quickstart for ClickHouse-2202-09-15.pdfAltinity Ltd
 
2022 SF Summit - Improving Developer Experience with CDK
2022 SF Summit - Improving Developer Experience with CDK2022 SF Summit - Improving Developer Experience with CDK
2022 SF Summit - Improving Developer Experience with CDKCasey Lee
 
Weather scraper for your data warehouse
Weather scraper for your data warehouseWeather scraper for your data warehouse
Weather scraper for your data warehouseFru Louis
 
Full Stack Visualization: Build A React App With A Sankey Diagram
Full Stack Visualization: Build A React App With A Sankey DiagramFull Stack Visualization: Build A React App With A Sankey Diagram
Full Stack Visualization: Build A React App With A Sankey DiagramNeo4j
 
リーンスタートアップにおける、実装やライブ配信基盤の共通化 村田紘司
リーンスタートアップにおける、実装やライブ配信基盤の共通化 村田紘司リーンスタートアップにおける、実装やライブ配信基盤の共通化 村田紘司
リーンスタートアップにおける、実装やライブ配信基盤の共通化 村田紘司紘司 村田
 

Similar to Spring Data JPAによるデータアクセス徹底入門 #jsug (17)

ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
 
Spring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjugSpring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjug
 
Java EE 8新機能解説 -Bean Validation 2.0編-
Java EE 8新機能解説 -Bean Validation 2.0編-Java EE 8新機能解説 -Bean Validation 2.0編-
Java EE 8新機能解説 -Bean Validation 2.0編-
 
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
 
保守・追加開発に必要な「Springの正しい知識」とは?20171109
保守・追加開発に必要な「Springの正しい知識」とは?20171109保守・追加開発に必要な「Springの正しい知識」とは?20171109
保守・追加開発に必要な「Springの正しい知識」とは?20171109
 
JSUG SpringOne 2017報告会
JSUG SpringOne 2017報告会JSUG SpringOne 2017報告会
JSUG SpringOne 2017報告会
 
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
 
How Zocdoc Achieves Automatic Threat Detection & Remediation with Security as...
How Zocdoc Achieves Automatic Threat Detection & Remediation with Security as...How Zocdoc Achieves Automatic Threat Detection & Remediation with Security as...
How Zocdoc Achieves Automatic Threat Detection & Remediation with Security as...
 
BREWBEANS.sql.txtDROP TABLE BB_Department CASCADE CONSTRAINTS .docx
BREWBEANS.sql.txtDROP TABLE BB_Department CASCADE CONSTRAINTS .docxBREWBEANS.sql.txtDROP TABLE BB_Department CASCADE CONSTRAINTS .docx
BREWBEANS.sql.txtDROP TABLE BB_Department CASCADE CONSTRAINTS .docx
 
Real-time Data Updates for Neo4j Using GraphQL Subscriptions
Real-time Data Updates for Neo4j Using GraphQL SubscriptionsReal-time Data Updates for Neo4j Using GraphQL Subscriptions
Real-time Data Updates for Neo4j Using GraphQL Subscriptions
 
Altinity Quickstart for ClickHouse-2202-09-15.pdf
Altinity Quickstart for ClickHouse-2202-09-15.pdfAltinity Quickstart for ClickHouse-2202-09-15.pdf
Altinity Quickstart for ClickHouse-2202-09-15.pdf
 
2022 SF Summit - Improving Developer Experience with CDK
2022 SF Summit - Improving Developer Experience with CDK2022 SF Summit - Improving Developer Experience with CDK
2022 SF Summit - Improving Developer Experience with CDK
 
Using Inner-Joins (SQL)
Using Inner-Joins (SQL)Using Inner-Joins (SQL)
Using Inner-Joins (SQL)
 
Inner joins
Inner joinsInner joins
Inner joins
 
Weather scraper for your data warehouse
Weather scraper for your data warehouseWeather scraper for your data warehouse
Weather scraper for your data warehouse
 
Full Stack Visualization: Build A React App With A Sankey Diagram
Full Stack Visualization: Build A React App With A Sankey DiagramFull Stack Visualization: Build A React App With A Sankey Diagram
Full Stack Visualization: Build A React App With A Sankey Diagram
 
リーンスタートアップにおける、実装やライブ配信基盤の共通化 村田紘司
リーンスタートアップにおける、実装やライブ配信基盤の共通化 村田紘司リーンスタートアップにおける、実装やライブ配信基盤の共通化 村田紘司
リーンスタートアップにおける、実装やライブ配信基盤の共通化 村田紘司
 

More from Masatoshi Tada

Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_cccPivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_cccMasatoshi Tada
 
基礎からのOAuth 2.0とSpring Security 5.1による実装
基礎からのOAuth 2.0とSpring Security 5.1による実装基礎からのOAuth 2.0とSpring Security 5.1による実装
基礎からのOAuth 2.0とSpring Security 5.1による実装Masatoshi Tada
 
Getting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafGetting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafMasatoshi Tada
 
Java EEハンズオン資料 JJUG CCC 2015 Fall
Java EEハンズオン資料 JJUG CCC 2015 FallJava EEハンズオン資料 JJUG CCC 2015 Fall
Java EEハンズオン資料 JJUG CCC 2015 FallMasatoshi Tada
 
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新Masatoshi Tada
 
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho ltNetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho ltMasatoshi Tada
 
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2Masatoshi Tada
 
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_cccJPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_cccMasatoshi Tada
 

More from Masatoshi Tada (8)

Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_cccPivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
 
基礎からのOAuth 2.0とSpring Security 5.1による実装
基礎からのOAuth 2.0とSpring Security 5.1による実装基礎からのOAuth 2.0とSpring Security 5.1による実装
基礎からのOAuth 2.0とSpring Security 5.1による実装
 
Getting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafGetting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with Thymeleaf
 
Java EEハンズオン資料 JJUG CCC 2015 Fall
Java EEハンズオン資料 JJUG CCC 2015 FallJava EEハンズオン資料 JJUG CCC 2015 Fall
Java EEハンズオン資料 JJUG CCC 2015 Fall
 
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
 
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho ltNetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
 
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
 
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_cccJPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
 

Recently uploaded

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

Spring Data JPAによるデータアクセス徹底入門 #jsug

  • 1. (C) CASAREAL, Inc. All rights reserved. 1
  • 2. (C) CASAREAL, Inc. All rights reserved. 2
  • 3. (C) CASAREAL, Inc. All rights reserved. 3
  • 4. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 😅 ▸ ▸ 4
  • 5. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ 5
  • 6. (C) CASAREAL, Inc. All rights reserved. ▸ 6
  • 7. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ ▸ 7
  • 8. (C) CASAREAL, Inc. All rights reserved. 8 Spring Web 4 Spring MVC Spring Boot Developer 2 Spring Boot Spring Cloud Services 3 Spring Cloud Microservices
  • 9. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 9
  • 10. (C) CASAREAL, Inc. All rights reserved. 10
  • 11. (C) CASAREAL, Inc. All rights reserved. 11
  • 12. (C) CASAREAL, Inc. All rights reserved. ▸ 12
  • 13. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ 13
  • 14. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 14
  • 15. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 15 ※ JPA 2.1(Java EE 7) 

  • 16. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 16
  • 17. (C) CASAREAL, Inc. All rights reserved. ▸ 17 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
  • 18. (C) CASAREAL, Inc. All rights reserved. ▸ 18 <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>2.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>5.2.12.Final</version> </dependency>
  • 19. (C) CASAREAL, Inc. All rights reserved. ▸ 19 logging.level.org.hibernate.SQL=debug logging.level.org.hibernate.type.descriptor.sql.BasicBinder= trace <logger name="org.hibernate.SQL" level="DEBUG" /> <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" /> ▸ ▸ ※hibernate.show_sql=true
  • 20. (C) CASAREAL, Inc. All rights reserved. ▸ 20 spring.jpa.properties.hibernate.format_sql=true ▸ ▸ ▸
  • 21. (C) CASAREAL, Inc. All rights reserved. 21
  • 22. (C) CASAREAL, Inc. All rights reserved. 22 
 DB
  • 23. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 23 @Entity public class Product { @Id private Integer id; private String name; // setter/getter }
  • 24. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 
 24
  • 25. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 
 25
  • 26. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 
 26
  • 27. (C) CASAREAL, Inc. All rights reserved. 27 NEW new MANAGED DETACHED REMOVED
  • 28. (C) CASAREAL, Inc. All rights reserved. 28 find() persist() 1 remove() 1 merge() detach() flush() DB clear() refresh() DB
  • 29. (C) CASAREAL, Inc. All rights reserved. 29 persist() detach()
 clear() merge() remove() flush() flush() refresh() find()
 JPQL detach()
 clear()
  • 30. (C) CASAREAL, Inc. All rights reserved. 30 EntityManager em = …; // 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 

  • 31. (C) CASAREAL, Inc. All rights reserved. 31 Product product = new Product(“ ”, 100000L); em.persist(product); ▸ ▸ insert into product (category_id, name, price, vendor_id, id) values (?, ?, ?, ?, ?)
  • 32. (C) CASAREAL, Inc. All rights reserved. 32 // find() MANAGED Product product = em.find(Product.class, 1); // product.setName(" "); // ( OK) em.flush(); ▸
  • 33. (C) CASAREAL, Inc. All rights reserved. 33 select … from product product0_ where product0_.id=? binding parameter [1] as [INTEGER] - [1] update product set category_id=?, name=?, price=?, vendor_id=? where id=? binding parameter [1] as [INTEGER] - [1] binding parameter [2] as [VARCHAR] - [ ] binding parameter [3] as [BIGINT] - [100000] binding parameter [4] as [INTEGER] - [1] binding parameter [5] as [INTEGER] - [1]
  • 34. (C) CASAREAL, Inc. All rights reserved. 34 Product product = new Product(); product.setId(1); product.setName(“ "); // merge() em.merge(product); em.flush(); ▸
  • 35. (C) CASAREAL, Inc. All rights reserved. 35 select … from product product0_ where product0_.id=? binding parameter [1] as [INTEGER] - [1] update product set category_id=?, name=?, price=?, vendor_id=? where id=? binding parameter [1] as [INTEGER] - [null] binding parameter [2] as [VARCHAR] - [ ] binding parameter [3] as [BIGINT] - [null] binding parameter [4] as [INTEGER] - [null] binding parameter [5] as [INTEGER] - [1] ▸
  • 36. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 36 Product mergedProduct = em.merge(product); // MANAGED assertTrue(em.contains(mergedProduct)); // assertFalse(em.contains(product));
  • 37. (C) CASAREAL, Inc. All rights reserved. 37 // find() MANAGED Product product = em.find(Product.class, 30); // REMOVED em.remove(product); // ( OK) em.flush(); ▸
  • 38. (C) CASAREAL, Inc. All rights reserved. 38 select … from product product0_ where product0_.id=? binding parameter [1] as [INTEGER] - [30] delete from product where id=? binding parameter [1] as [INTEGER] - [30]
  • 39. (C) CASAREAL, Inc. All rights reserved. 39 // find() MANAGED Product product = em.find(Product.class, 30); // REMOVED em.remove(product); // DETACHED em.detach(product); // DETACHED DB em.flush(); ▸
  • 40. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ 40
  • 41. (C) CASAREAL, Inc. All rights reserved. 41
  • 42. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 42
  • 43. (C) CASAREAL, Inc. All rights reserved. 43 TypedQuery<Product> query = 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(); ▸ ▸
  • 44. (C) CASAREAL, Inc. All rights reserved. 44 select product0_.id 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=? ▸ 

  • 45. (C) CASAREAL, Inc. All rights reserved. 45 SELECT FROM [AS] WHERE . <= : ▸ ▸ 
 ▸
  • 46. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 46 SELECT new com.example.demo.dto.CountDto( od.product.id, COUNT(od)) FROM OrderDetail od GROUP BY od.product.id
  • 47. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ 47
  • 48. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 48
  • 49. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 49
  • 50. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 50
  • 51. (C) CASAREAL, Inc. All rights reserved. 51
  • 52. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 52 @Entity public class Product { … @ManyToOne @JoinColumn(name="vendor_id") private Vendor vendor; } @Entity public class Vendor { … }
  • 53. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 53
  • 54. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 54 @Entity public class Product { … @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="vendor_id") private Vendor vendor; }
  • 55. (C) CASAREAL, Inc. All rights reserved. 55 select ( ) 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
  • 56. (C) CASAREAL, Inc. All rights reserved. ▸ 56 em.getTransaction().begin(); Product p = em.find(Product.class, 1); em.getTransaction().rollback(); Vendor v = p.getVendor(); String n = v.getName(); //
  • 57. (C) CASAREAL, Inc. All rights reserved. 57 @Entity public class Product { @ManyToOne(fetch = FetchType.EAGER) private Vendor vendor; } Product p = em.find(Product.class, 1); Vendor v = p.getVendor(); // select ( ) from product product0_ left outer join vendor vendor2_ on product0_.vendor_id=vendor2_.id where product0_.id=? 1 SELECT
  • 58. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 
 ▸ 58
  • 59. (C) CASAREAL, Inc. All rights reserved. 59 // 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); } }
  • 60. (C) CASAREAL, Inc. All rights reserved. 60 // order_summary SELECT 1 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); } }
  • 61. (C) CASAREAL, Inc. All rights reserved. 61 select ordersumma0_.id 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 

  • 62. (C) CASAREAL, Inc. All rights reserved. ▸ 62 // order_summary SELECT 1 List<OrderSummary> list = em.createQuery( "SELECT os FROM OrderSummary os" + " JOIN FETCH os.orderDetailList" + , OrderSummary.class) .getResultList();
  • 63. (C) CASAREAL, Inc. All rights reserved. 63 select 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=? JOIN 

  • 64. (C) CASAREAL, Inc. All rights reserved. 64 OrderSummary{id=1, orderTimestamp=2017-04-01T10:00} OrderDetail{id=1, amount=2} OrderDetail{id=2, amount=2} OrderDetail{id=3, amount=2} OrderSummary{id=1, orderTimestamp=2017-04-01T10:00} OrderDetail{id=1, amount=2} OrderDetail{id=2, amount=2} OrderDetail{id=3, amount=2} OrderSummary{id=1, orderTimestamp=2017-04-01T10:00} OrderDetail{id=1, amount=2} OrderDetail{id=2, amount=2} OrderDetail{id=3, amount=2} OrderSummary{id=2, orderTimestamp=2017-04-01T10:00} OrderDetail{id=4, amount=2} OrderDetail{id=5, amount=2} 

  • 65. (C) CASAREAL, Inc. All rights reserved. 65 // order_summary SELECT 1 List<OrderSummary> list = em.createQuery( "SELECT DISTINCT os FROM OrderSummary os" + " JOIN FETCH os.orderDetailList" + , OrderSummary.class) .getResultList();
  • 66. (C) CASAREAL, Inc. All rights reserved. 66 select 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 

  • 67. (C) CASAREAL, Inc. All rights reserved. 67 OrderSummary{id=1, orderTimestamp=2017-04-01T10:00} OrderDetail{id=3, amount=2} OrderDetail{id=1, amount=2} OrderDetail{id=2, amount=2} OrderSummary{id=2, orderTimestamp=2017-04-01T10:00} OrderDetail{id=5, amount=2} OrderDetail{id=6, amount=2} OrderDetail{id=4, amount=2} OrderSummary{id=9, orderTimestamp=2017-04-01T10:00} OrderSummary{id=7, orderTimestamp=2017-04-01T10:00} OrderSummary{id=6, orderTimestamp=2017-04-01T10:00} OrderSummary{id=5, orderTimestamp=2017-04-01T10:00} OrderSummary{id=4, orderTimestamp=2017-04-01T10:00} OrderSummary{id=3, orderTimestamp=2017-04-01T10:00} OrderSummary{id=8, orderTimestamp=2017-04-01T10:00} OrderSummary{id=10, orderTimestamp=2017-04-01T10:00} 

  • 68. (C) CASAREAL, Inc. All rights reserved. ▸ 68
  • 69. (C) CASAREAL, Inc. All rights reserved. // order_summary order_detail product JOIN OrderSummary orderSummary = em.createQuery( "SELECT os FROM OrderSummary os" + " JOIN FETCH os.orderDetailList od" + " JOIN FETCH od.product p" + " WHERE os.id = :id", OrderSummary.class) .setParameter("id", 1) .getSingleResult(); ▸ 69
  • 70. (C) CASAREAL, Inc. All rights reserved. 70 select ordersumma0_.id 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 

  • 71. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 71
  • 72. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 
 ▸ ▸ 72 https://www.casareal.co.jp/recruit/jobs/ ls_teacher.php
  • 73. (C) CASAREAL, Inc. All rights reserved. ▸ 
 ✕ 
 ✕ ▸ 
 
 
 
 73 https://www.casareal.co.jp/ls/service/shinjinseminar/course01
  • 74. (C) CASAREAL, Inc. All rights reserved. 74
  • 75. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 75
  • 76. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 76 Query query = em.createNativeQuery( "select id, name, price, vendor_id" + " from product where id = :id", Product.class); query.setParameter("id", 1); Product product = (Product) query.getSingleResult();
  • 77. (C) CASAREAL, Inc. All rights reserved. ▸ 77 Query query = em.createNativeQuery( "select id, name from product where id = :id"); query.setParameter("id", 1); // 0 id 1 name Object[] objs = (Object[]) query.getSingleResult(); Integer productId = (Integer) objs[0]; String productName = (String) objs[1];
  • 78. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 78
  • 79. (C) CASAREAL, Inc. All rights reserved. 79 @Entity @SqlResultSetMapping( name = "product_id_name", // classes = { @ConstructorResult(targetClass = ProductDto.class, columns = { @ColumnResult(name = "id"), @ColumnResult(name = "name") } ) } ) public class Product { … } 
 ※@SqlResultSetMappings @SqlResultSetMapping
  • 80. (C) CASAREAL, Inc. All rights reserved. 80 Query query = em.createNativeQuery( "select id, name from product where id = :id", "product_id_name"); // @SqlResultSetMapping name query.setParameter("id", 1); ProductDto productDto = (ProductDto) query.getSingleResult(); public class ProductDto { private Integer id; private String name; public ProductDto(Integer id, String name) { … } } 

  • 81. (C) CASAREAL, Inc. All rights reserved. ▸ 81 // H2 Database LEFT TypedQuery<Product> query = em.createQuery( "SELECT p FROM Product p" + " WHERE FUNCTION('LEFT', p.name, 2) = ' '", Product.class); List<Product> productList = query.getResultList();
  • 82. (C) CASAREAL, Inc. All rights reserved. ▸ 82 StoredProcedureQuery query = em.createStoredProcedureQuery(" ", .class); query.setParameter(" ", ); List< > list = (List< >) query.getResultList(); ※
  • 83. (C) CASAREAL, Inc. All rights reserved. ▸ 83 @Entity @Index(members = {"name"}) public class Product { … } ※ 
 ※@Indices @Index
  • 84. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 84
  • 85. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 85
  • 86. (C) CASAREAL, Inc. All rights reserved. 86
  • 87. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ 87
  • 88. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ 88
  • 89. (C) CASAREAL, Inc. All rights reserved. ▸ 89 public interface ProductRepository extends JpaRepository<Product, Integer> { // OK } ※@Repository
  • 90. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 90
  • 91. (C) CASAREAL, Inc. All rights reserved. 91 @Service public class ProductService { private final ProductRepository repo; @Autowired // DI public ProductService(ProductRepository repo) { this.repo = repo; } @Transactional public void insert(Product product) { repo.save(product); } } ※@Autowired Spring 4.3 
 1
  • 92. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 92 public interface ProductRepository extends JpaRepository<Product, Integer> { @Query("SELECT p FROM Product p JOIN FETCH p.vendor" + " WHERE p.id = :id") Product findByIdJoinFetch(@Param("id") Integer id); }
  • 93. (C) CASAREAL, Inc. All rights reserved. ▸ 93 public interface ProductRepository extends JpaRepository<Product, Integer> { @Modifying @Query("UPDATE Product p SET p.name = :name" + " WHERE p.id = :id") void updateName(@Param("name") String name, @Param("id") Integer id); }
  • 94. (C) CASAREAL, Inc. All rights reserved. ▸ 94 public interface ProductRepository extends JpaRepository<Product, Integer> { @Lock(LockModeType.PESSIMISTIC_READ) @Query("SELECT p FROM Product p JOIN FETCH p.vendor" + " WHERE p.id = :id") Product findByIdJoinFetch(@Param("id") Integer id); } ※ 
 https://www.slideshare.net/masatoshitada7/jpa20140518-ccc-r15-jjug-ccc
  • 95. (C) CASAREAL, Inc. All rights reserved. ▸ 95 public interface ProductRepository extends JpaRepository<Product, Integer> { @EntityGraph(" ") @Query("SELECT p FROM Product p JOIN FETCH p.vendor" + " WHERE p.id = :id") Product findByIdJoinFetch(@Param("id") Integer id); } ※ 
 https://blog.ik.am/entries/350
  • 96. (C) CASAREAL, Inc. All rights reserved. ▸ 96 public interface ProductRepository extends JpaRepository<Product, Integer> { // name List<Product> findByNameContaining(String keyword); }
  • 97. (C) CASAREAL, Inc. All rights reserved. 97 select product0_.id 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] - [% %]
  • 98. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 98
  • 99. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 99 

  • 100. (C) CASAREAL, Inc. All rights reserved. ▸ 100 @Entity public class Hoge { @CreatedBy String createdUser; @CreatedDate LocalDateTime createdDate; @LastModifiedBy String modifiedUser; @LastModifiedDate LocalDateTime lastModifiedDate; }
  • 101. (C) CASAREAL, Inc. All rights reserved. 101 @SpringBootApplication @EnableJpaAuditing(auditorAwareRef = "myAuditorAware") public class SpringDataJpaDaitokaiApplication { … } @Component public class MyAuditorAware implements AuditorAware<String> { @Override public Optional<String> getCurrentAuditor() { return Optional.of("user01");} } Spring Security 
 OK
  • 102. (C) CASAREAL, Inc. All rights reserved. 102 <entity-mappings> <persistence-unit-metadata> <persistence-unit-defaults> <entity-listeners> <entity-listener class="org.springframework.data.jpa.domain.support.AuditingEntityListene r" /> </entity-listeners> </persistence-unit-defaults> </persistence-unit-metadata> </entity-mappings> ▸ ▸
  • 103. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ 103
  • 104. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ 104
  • 105. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ ▸ 105
  • 106. (C) CASAREAL, Inc. All rights reserved. 106
  • 107. (C) CASAREAL, Inc. All rights reserved. ▸ 107 http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/reference/htmlsingle/#boot-features-jpa-in- web-environment
  • 108. (C) CASAREAL, Inc. All rights reserved. ▸ 108 spring.jpa.open-in-view=false
  • 109. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 109 @Entity public class Hoge { // Spring Boot @Column @Column(name=“foo_bar”) String fooBar; } http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/reference/htmlsingle/#howto-configure- hibernate-naming-strategy
  • 110. (C) CASAREAL, Inc. All rights reserved. ▸ 110 spring.jpa.hibernate.naming.physical-strategy=Strategy FQCN spring.jpa.hibernate.naming.implicit-strategy=Strategy FQCN
  • 111. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ 111 @SpringBootApplication @EntityScan(basePackages = { "com.example.demo.persistence.entity", "org.springframework.data.jpa.convert.threeten"}) public class SpringDataJpaDaitokaiApplication { … } http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/reference/htmlsingle/#howto-separate-entity- definitions-from-spring-configuration
  • 112. (C) CASAREAL, Inc. All rights reserved. 112
  • 113. (C) CASAREAL, Inc. All rights reserved. ▸ 113
  • 114. (C) CASAREAL, Inc. All rights reserved. 
 
 114 😅
  • 115. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ ▸ 115
  • 116. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ 116
  • 117. (C) CASAREAL, Inc. All rights reserved. ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ 117
  • 118. (C) CASAREAL, Inc. All rights reserved. ▸ 118