본문 바로가기

Java

(49)
[JPA] List<Entity> 비교 * 자바 List 비교 참고https://phyho.tistory.com/317 [JS] 배열값 비교 (include, '===') / Java_List 비교* 배열요소 비교 ( include ) const arr = [1, 2, 3, 4, 5];console.log(arr.includes(2)); // true * includes() 함수는 내부적으로 '===' 연산자를 사용하여 요소를 비교하기 때문에 다른 타입은 비교 불가능.const mixedArr =phyho.tistory.com [ Entity 클래스 ]@Entity@Getter@Setter@Builder@NoArgsConstructor@AllArgsConstructorpublic class Entity { private String id..
[JPA] findById, existsById, getById * findById(id)id에 해당하는 엔티티를 반환 (Optional)해당하는 엔티티가 없는경우 'Optional.empty()' 반환   * existsById(id)id에 해당하는 엔티티의 존재여부 반환 (boolean) 해당하는 엔티티가 있다면 첫번재 결과에서 바로 true를 리턴. (아래처럼 최적화된 select 쿼리 실행) Hibernate: select id from table where id=? limit 1  * getById(id)id에 해당하는 엔티티를 반환 (엔티티가 반드시 존재한다고 가정 )해당하는 엔티티가 없는 경우 'javax.persistence.EntityNotFoundException' 예외.
[JPA] Querydsl 벌크삭제 Querydsl 을 사용해서 벌크삭제를 해봤다. 아래와 같은 세개의 엔티티 클래스가 있다면, ' User ' , ' Order ', ' Post '=> 각 User는 여러 Order를 가질 수 있고, 또한 여러 Post를 가질 수 있음. User 엔티티 삭제로직을 처음에는 아래처럼 만들었다.(User의 pk가 'userId'와 'userCode'라고 가정. 세세한 로직은 생략.)if (!deleteList.isEmpty()) { List delList = new ArrayList(); for (Map del : deleteList) { String userId = String.valueOf(del.get("userId")); String userCode = Stri..
[오류 / IntelliJ] error: (패키지명) does not exist error: (패키지경로) does not exist import (경로); Cannot resolve symbol ~ 패키지명을 한번 변경했다고 계속 위와같은 오류가 났다. import문 확인해봐도 경로에 문제는 없었다. Rebuild Project 해줬더니 해결!
[오류] HttpMessageNotReadableException : Required request body is missing DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public org.springframework.http.ResponseEntity ... 경로...Controller.deleteEntity(java.util.Map)] 프론트 쪽에서 아래의 함수로 서버에 요청을 보내고 export const deleteEntityApi = async (param) => { const response = await api.delete(`ent/${param}`); return response.data; } ** ..
[오류 / JPA] dentifier of (엔티티) an instance of Entity was altered from A to B identifier of an instance of (Entity) was altered[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.orm.jpa.JpaSystemException: identifier of an instance of (엔티티) was altered from   (  A  )    to   (  B  )    with root cause 본질적으로는 JPA 영속성 관련 문제인데, (JPA에서는 객체들을 우선 영속성 컨텍스트에 등록(flush) 후..
[오류 / JPA] Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table ['(테이블명)'] ( SchemaManagementException 오류 ) JPA 에서는 db테이블과 엔티티를 매핑해줘야 하는데, 이 때 테이블을 인식하지 못해서 발생한 오류. 원래는 @Table(name = "테이블명") 이렇게만 써줬는데, schema를 명시해주지 않아서, 테이블을 인식하지..
[오류] JSON parse error: Cannot deserialize value of type `java.util.ArrayList<java.util.Map<java.lang.String,java.lang.Object>>` from Object value (token `JsonToken.START_OBJECT`) JSON parse error: Cannot deserialize value of type `java.util.ArrayList` from Object value (token `JsonToken.START_OBJECT`) 데이터 타입 불일치 오류. => Postman에서 보내는 parameter의 데이터 타입을 잘못 써줘서 났던 오류였다. ( [ ] 괄호를 빼먹음 ) 컨트롤러에서 parameter를 List 타입으로 받아줬기 때문에 아래처럼 보내줘야 한다. ** Postman에서 쌍따옴표("")를 사용해야 오류가 안남. [ {"id" : "testId", "name" : "testNm"}, {"id" : "testId2", "name" : "testNm2"} ] 프론트에서 데이터를 json형태로 서버로 ..