본문 바로가기
Java/Spring

java.lang.IllegalAccessException: Class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor can not access a member of class org.example.entity.BaseEntity with modifiers "public"

by java개발자 2021. 5. 9.

모든 Entity는 BaseEntity를 상속한다.

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import lombok.Getter;


@Getter
@EntityListeners(value = { AuditingEntityListener.class })
@MappedSuperclass
abstract class BaseEntity {

	@CreatedDate
	@Column(updatable = false)
	private LocalDateTime regDate;

	@LastModifiedDate
	private LocalDateTime updateDate;
}

Cart - Product

N:1관계(LAZY) 일때

Cart를 조회하고,

product = getProduct();

product.getName()을 실행하면,

(LAZY) 그 때 product를 DB에서 조회한다. 초기화.

이후부터는 product.getId() 등을 호출하면, 방금 조회한 DB에서 데이터를 가져온다.

 

그런데, product.getRegDate()를 실행하면, 에러가 발생한다.

java.lang.IllegalAccessException: Class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor can not access a member of class org.example.entity.BaseEntity with modifiers "public"

프록시 객체에서는 @MappedSuperclass 내의 public 함수에 접근이 안되나?? 왜????

 

해결:

일단, Cart를 조회할 때, @EntityGraph를 이용해서 Product를 같이 조회하면 되긴 하는데....

 

*리플렉션에서 답을 찾을 수 있을듯....TODO.. (또는 해결할 어노테이션이 있을까?

java.lang.IllegalAccessException: Class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor can not access a member of class org.example.entity.BaseEntity with modifiers "public"
	at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
	at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown Source)
	at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor.intercept(ByteBuddyInterceptor.java:56)
	at org.hibernate.proxy.ProxyConfiguration$InterceptorDispatcher.intercept(ProxyConfiguration.java:95)
	at org.example.entity.Product$HibernateProxy$vulS6Qf5.getRegDate(Unknown Source)

 

 

해결::::::::

BaseEntity class를 public으로.ㅠㅠ