JpaMain.class
try {
Member member = new Member();
member.setUsername("member1");
em.persist(member);
// flush -> commit, query
// dbconn.executeQuery("select * from member");
List<Member> resultList = em.createNamedQuery("select MEMBER_ID, city, street, zipcode, USERNAME from MEMBER", Member.class)
.getResultList();
for (Member member1 : resultList) {
System.out.println("member1 = " + member1);
}
tx.commit();
} catch (Exception e) {
tx.rollback();
e.printStackTrace();
} finally {
em.close();
}
emf.close();
error log
java.lang.IllegalArgumentException: No query defined for that name [select MEMBER_ID, city, street, zipcode, USERNAME from MEMBER]
at org.hibernate.internal.AbstractSharedSessionContract.buildQueryFromName(AbstractSharedSessionContract.java:828)
at org.hibernate.internal.AbstractSharedSessionContract.createNamedQuery(AbstractSharedSessionContract.java:926)
at org.hibernate.internal.AbstractSessionImpl.createNamedQuery(AbstractSessionImpl.java:23)
at hellojpa.JpaMain.main(JpaMain.java:35)
4월 08, 2022 11:51:22 오후 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:h2:tcp://localhost/~/test]
<출처 김영한: 자바 ORM 표준 JPA 프로그래밍 - 기본편 >
https://www.inflearn.com/course/ORM-JPA-Basic/dashboard
'Spring > JPA' 카테고리의 다른 글
플러시 & 준영속 상태 정리 (0) | 2022.04.12 |
---|---|
내부 동작 방식 - 영속성 컨텍스트 2 (0) | 2022.04.12 |
내부 동작 방식 - 영속성 컨텍스트 1 (0) | 2022.04.12 |
데이터베이스 스키마 자동생성 - create-drop (0) | 2022.04.04 |
JPA 시작하기 - 애플리케이션 개발 & error (0) | 2022.04.04 |