-
카테고리
-
세부 분야
백엔드
-
해결 여부
해결됨
jpa와 mysql을 붙일때요..
21.02.13 12:34 작성 조회수 154
0
강의 항상 잘 듣고 있습니다^^!!
수업과는 조금? 상관이 없는 질문 일수도 있는데요. 개인적으로 복습해보려고 아마존 S2에 Mysql 테이블 생성해서 데이터 넣고 제가 jpa, jpa-data 등 이용해서 자료 한번 조회하는 간단한 프로젝트를 해보고 있습니다.
그런데 ㅠㅠ DB에 데이터는 정상적으로 들어가는데 JPA가 쏘는 쿼리가 영 이상한지 계속 오류가 뜨네요.
무엇이 잘못된 거일까요?
작동시키려는 쿼리? 메소드는 단순합니다. 전체 정보 불러오기 입니다.
@GetMapping("/findall")
public String findAll() {
String result = "";
for (Site site : siteRepository.findAll()) {
result += site.toString() + "<br/>";
}
return result;
}
application.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://54.xxx1xx.x3/shark1
username:
password:
jpa:
hibernate:
ddl-auto: none
show-sql: true
database: mysql
data:
jpa:
repositories:
enabled: true
siteRepository.java
@Transactional(readOnly = true)
public interface SiteRepository extends JpaRepository<Site, Long> {
List<Site> findByArea1(String area1);
}
Site.java
@Entity
@Getter @Setter
@Table(name = "site")
public class Site {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long site_id;
private String name;
private String location;
private String area1;
private String area2;
private String info;
}
소스는 이러하구요 쿼리가 나갈때
findall() 호출하면
Hibernate: select site0_.site_id as site_id1_0_, site0_.area1 as area2_0_, site0_.area2 as area3_0_, site0_.info as info4_0_, site0_.location as location5_0_, site0_.name as name6_0_ from site site0_
이런식으로 나갑니다 ㅠㅠㅠ
DB 칼럼도 도메인이랑 모두 맞춰놨는데요 ㅠㅠ
제가 뭔가 JPA에 대해 설정을 잘못한게 있을까요?
도움 꼭 부탁드립니다. ㅠㅠ
답변을 작성해보세요.
1
0
김영한
지식공유자2021.02.13
Jin K님 위에 적어두신 정보는 바로 삭제해주세요. 해킹 당할 수 있습니다.(비밀번호도 즉시 변경해주세요. 검색엔진이 이미 긁어 갔을 수 있습니다.)
@RespnoseBody가 빠졌네요. 이게 있어야 HTTP Body에 직접 메시지를 뿌립니다.
@ResponseBody
@GetMapping("/findall")
public String findAll() {
감사합니다.
0
김영한
지식공유자2021.02.13
안녕하세요. Jin K님
다음과 같이 쿼리가 나가는 것은 정상입니다. 하이버네이트가 쿼리의 별칭을 site0_처럼 좀 기계적으로 만듭니다.
Hibernate: select site0_.site_id as site_id1_0_, site0_.area1 as area2_0_, site0_.area2 as area3_0_, site0_.info as info4_0_, site0_.location as location5_0_, site0_.name as name6_0_ from site site0_
오류 문제는 다른 문제로 보이고, 전체 오류 메시지를 남겨주시면 도움을 드릴게요.
감사합니다.
답변 3