際際滷
Submit Search
????????? ???????????? ????? JPA
?
Download as PPTX, PDF
?
21 likes
?
10,296 views
?? ?
Follow
SLiPP 1? ???, ??? ????? ?? JPA ?? ?????.
Read less
Read more
1 of 59
Download now
Downloaded 52 times
More Related Content
????????? ???????????? ????? JPA
1.
??? ????? ??
JPA 2015.12.12 ???(woniper)
2.
???(woniper) http://blog.woniper.net https://github.com/woniper leekw3747@gmail.com
3.
?? JPA ?? JDBC?? JPA?? ???
???? ????
4.
JPA(Java Persistence API)
??
5.
Java ORM(Object-Relational Mapping)
?? F/W RDB? ??? ??(??), ?? Hibernate, Eclipse Link, TopLink Essensials ???
6.
JDBC?? JPA??
7.
JDBC Connection Query ?? Resource Close
8.
xBatis <select id="select" parameterType="java.lang.Integer"
resultType=^User ̄> select userId, username, password from User where userId = #{userId} </select>
9.
Query ?? ???
????
10.
JPA
11.
EntityManager em =
entityManagerFactory.createEntityManager(); 1. Insert em.persist(user); 2. Select User user = em.find(User.class, 1); 3. Update user.setUsername("update Name"); user.setPassword("1111"); 4. Delete em.remove(user);
12.
Connection, close Query ??
?? ? ?? ??? ?? ??
13.
???(Entity) ????
14.
@Entity @Table(name = "User") public
class User { @Id @GeneratedValue private Integer userId; @Column(name = "username", nullable = false) private String username; @Column(name = "password", nullable = false) private String password; @Column(name = "nickName", nullable = true) private String nickName; }
15.
USER ???(NEW) USER ??(Managed) ??? ???? persist() USER ??(Removed) remove() USER ???(Detached) detach()
16.
??? ????
17.
??
18.
?? ?? SQL(SQL
???) ?? ?? ?? 1? ?? ??? ??? ?? ??
19.
EntityManagerFactory emf =
Persistence.createEntityManagerFactory(^persistence"); 1? ?? ?? @ID Entity Snapshot SQL ??? EntityManager em1 = emf.createEntityManager(); em1 1? ?? ?? @ID Entity Snapshot SQL ??? EntityManager em2 = emf.createEntityManager(); em2
20.
1? ?? ?? @ID
Entity Snapshot 1 User User SQL ?? ? ??? ???? J D B C
21.
??? ????? ???
???? ?
22.
??(persist)
23.
EntityManager em =
emf.createEntityManager(); em.getTransaction().begin(); // ? ?? ?? User user = new User("wons", "12345", "woniper"); // ?? ?? // 1? ?? ??, Query ?? ? ?? em.persist(user); // ??? ?? // SQL ??? Query DB? ?? em.getTransaction().commit(); em.close();
27.
??(find)
28.
EntityManager em =
emf.createEntityManager(); em.getTransaction().begin(); // ?? ??? User user = em.find(User.class, 1); // ??? ?? em.getTransaction().commit(); em.close();
32.
??(?? ?? ??)
33.
EntityManager em =
emf.createEntityManager(); em.getTransaction().begin(); // ?? ?? // 1? ?? ?? User user = em.find(User.class, 1); // ?? ?? ?? user.setUserName("updateName"); user.setPassword("1111"); user.setNickName("updateNick"); // ??? ?? em.getTransaction().commit(); em.close();
37.
??(remove)
38.
EntityManager em =
emf.createEntityManager(); em.getTransaction().begin(); // ?? ?? // 1? ?? ?? User user = em.find(User.class, 1); // ?? ??, Query ?? ? ?? em.remove(user); // SQL ??? Query DB? ?? em.getTransaction().commit(); em.close();
42.
???? ???? ?? commit()
?? ? flush()
43.
merge
44.
? ?? ???
-> ?? ???
45.
merge? ???? ??
46.
?? ??? ->
? ?? ???
47.
em.clear(); em.detach(user); em.close();
48.
EntityManager em =
emf.createEntityManager(); em.getTransaction().begin(); // 1. ?? ??, username == woniper User user1 = em.find(User.class, 1); // 2. ??? ?? em.detach(user1); // 3. username ?? ?? user.setUserName(^lee-kyung-won"); // 4. ?? ?? em.merge(user1); em.getTransaction().commit(); em.close();
49.
EntityManager em =
emf.createEntityManager(); em.getTransaction().begin(); // 5. username ?? ??? User user2 = em.find(User.class, 1); em.getTransaction().commit(); em.close();
50.
user2? username? lee-kyung-won
54.
??? ??? ???
??? merge : update ??? ??? merge : insert
55.
????
57.
http://www.tutorialspoint.com/jpa/ http://www.objectdb.com/ https://en.wikibooks.org/wiki/Java_ Persistence
58.
http://goo.gl/xzpTdK https://goo.gl/sqmO9p https://goo.gl/GhsI4Q https://goo.gl/GpQzeL
59.
?????.
Editor's Notes
#2:
??
#3:
??, 3??, ??? ??? ???
#4:
2?? ?? JDBC,xBatis,JPA ?? JPA?? ?? ??? ??? ????
#5:
?? ??
#6:
?? ORM ORM == RDB? ??? ?? ? ?? (?? ??) ?? interface ?? -> ??? Hibernate? ???? ??
#8:
?? ??? ?? X 3?? ?? ?? X
#9:
JDBC? ?? -> Connection, Close, ?? ??? ??? ?? S??? Map<> ???
#10:
??? JPA? ?? ?? X ORM? ???? ??? ??? ?? ??(?? X)
#12:
EntityManager ??? ?? ?? update(?? ?? ??)
#13:
Connection, Close, ?? ?? ?? JPA? CRUD? ??? ?? ?? X
#14:
??? ?? ??? ???? ???? ?? ??? ????
#15:
??? -> DTO, VO ????? ?? ??? ?? X
#16:
4?? ??? ?? new ???(???) -> ?? ?? ??? ???? ?? ?? ??? ?? -> ?? ??? (persist) ?? ?? -> remove ??? ?? -> ??? ???(detach) ?? ??? ??? ?? ??
#17:
??? ??? ???? ??!!!
#19:
?? ?? X
#20:
EntityManagerFactory persistence ?? -> META-INF/persistence.xml -> ??? ?? X EntityManager ?? -> ??? ???? ?? ?? se, spring?? ?? ???(????)
#21:
? ??? ???? ?? ??? ? ??? ??? X, EntityManager? ?? JDBC? ??? SQL ???(?? ?? SQL? ??), DB?? ?? ??? ?? 1? ?? ?? @ID == ??? Entity == ??? ??? Snapshot == ?? ???
#22:
CRUD ??? ??
#24:
????? ?? ?? ?? ?? ??
#26:
1? ?? ??? ??? ?? ??
#27:
flush? Commit?? ?? ?? ??(??? ??)
#31:
1? ??? ??? DB?? X
#32:
?? ? ??
#34:
update ??? X ?? ?? ??
#35:
commit?? ? flush ??(??? ???, ?? ???)
#36:
??? ?? update ?? ?? ? ??
#37:
?? ??? ??? DB? ??
#40:
1? ?? ?? ??
#41:
?? ?? ? ??
#42:
?? ??? DB? ??
#43:
???? ????? ?? flush? ??? ????? DB? ??? commit? ??? DB? ??
#44:
?? ?? ?? ?? ??? ? ?? ?? ????
#48:
clear : ?? ?? -> ?? ?? ?? ?? detach : ?? ??? ?? close : EntityManager ??
#49:
username == woniper?? ?? ?? ??
#50:
?? ?? ?? ?? -> username? ???? ?????
#52:
User1 == lee-kyung-won Entity? username == woniper ???? ?? ? ??
#53:
User1? Entity??? ??(?? ???)
#54:
update
#55:
? ??? update insert? ?? ?? ???? ?? ? 3?? ??
#56:
?? ??? ??!!!
#57:
??? ?? ? ???? ??. ???? ??. A/S? ????
#58:
???
#59:
???
#60:
?? ??? ?? ?? ???? ?? ??? ??? ??????!!
Download