최대 절전 모드 5.0 + 춘분 4.5.0 및 사용자 정의 UserType (hibernate 5.0 + equinox 4.5.0 and custom UserType)


문제 설명

최대 절전 모드 5.0 + 춘분 4.5.0 및 사용자 정의 UserType (hibernate 5.0 + equinox 4.5.0 and custom UserType)

비관리 JPA 모드에서 Hibernate 5.0 Osgi 번들이 Equinox 4.5.0과 함께 작동하도록 할 수 있었습니다. 하지만 한 가지 문제가 있습니다. 내 엔티티 중 하나에서 사용자 정의 UserType(예: EnhancedUserType을 구현하는 TestTypeMapType)을 사용할 때 다음 예외가 발생합니다.

org.hibernate.MappingException: Could not determine type for: com.xxx.yyy.TestTypeMapType, at table: TestTable, for columns: [org.hibernate.mapping.Column(testType)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:390)

Hibernate 소스에서 SimpleValue.java를 확인할 때 그것은 org.hibernate.internal.util.Reflecthelper를 사용하여 아래 코드 줄로 유형 정보를 생성하고

ReflectHelper.classForName(typeName);

ReflectHelper가 아래 줄을 사용하여 유형 정보를 생성한다는 것

try {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader != null) {
        return classLoader.loadClass(typeName);
    }
}
catch(Throwable ignore){}

return Class.forName(typeName);

classLoader.loadClass와 Class.forName 모두 아래 예외를 던집니다.

java.lang.ClassNotFoundException: com.xxx.yyy.TestTypeMapType cannot be found by org.hibernate.core_5.0.2.Final

하지만 EntityManagerFactory를 생성하는 번들에서 직접 ReflectHelper.classForName 내용을 실행하면, 사용자 정의 UserType의 유형 정보를 성공적으로 생성할 수 있습니다. 특히 아래 예제의 경우 line‑A와 line‑B는 작동하지만 line‑C에서는 예외가 발생합니다.

try {
    Class<?> typeClass = null;

    // A
    typeClass = Thread.currentThread().getContextClassLoader().loadClass("com.xxx.yyy.TestTypeMapType");

    // B
    typeClass = Class.forName("com.xxx.yyy.TestTypeMapType");

    // C
    typeClass = ReflectHelper.classForName("com.xxx.yyy.TestTypeMapType");
}
catch(Exception e){}

osgi 환경의 최대 절전 모드에서 내 사용자 지정 UserType을 검색할 수 있도록 어떻게 해야 하나요?

p>

PS: 다른 Entity 클래스, 언어, jdbc 드라이버 등에 문제가 없습니다. 또한 ReflectHelper.classForName은 더 이상 사용되지 않으며 ClassLoaderService 또는 ClassLoaderAccess를 사용하는 것이 좋습니다. 최대 절전 모드 버그인가요?

감사합니다...

다른 Entity 클래스, 방언, jdbc 드라이버 등에 문제가 없습니다. 또한 ReflectHelper.classForName은 더 이상 사용되지 않으며 ClassLoaderService 또는 ClassLoaderAccess를 사용하는 것이 좋습니다. 최대 절전 모드 버그인가요?

감사합니다...

다른 Entity 클래스, 방언, jdbc 드라이버 등에 문제가 없습니다. 또한 ReflectHelper.classForName은 더 이상 사용되지 않으며 ClassLoaderService 또는 ClassLoaderAccess를 사용하는 것이 좋습니다. 최대 절전 모드 버그인가요?

감사합니다...


참조 솔루션

방법 1:

You need to use TypeContributor extension point as described here.

https://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html#_extension_points

Example how it is done is at hibernate envers:

https://github.com/hibernate/hibernate‑orm/blob/master/hibernate‑envers/src/main/resources/OSGI‑INF/blueprint/blueprint.xml

NOTE: You should register type contributor in the bundle that does not use entity manager instance directly or indirectly. Otherwise your type contributor will not be used for entity manager creation. I spent a lot of time debugging this. It is better to have a separate bundle just for user types.

(by exozuser1936595)

참조 문서

  1. hibernate 5.0 + equinox 4.5.0 and custom UserType (CC BY‑SA 2.5/3.0/4.0)

#equinox #osgi #hibernate #compositeusertype #jpa






관련 질문

Eclipse에서 OSGi 래퍼 번들을 실행할 수 없습니다. .jar은 잘 빌드되고 있지만 파일을 대상/클래스에 복사하려면 어떻게 해야 합니까? (Can't run OSGi wrapper bundle in Eclipse; .jar is building okay, but how do I also copy files into target/classes?)

최대 절전 모드 5.0 + 춘분 4.5.0 및 사용자 정의 UserType (hibernate 5.0 + equinox 4.5.0 and custom UserType)

Domino에 OSGi 서블릿 배치(IBM 프리젠테이션) - 404 오류 (Deploying OSGi Servlet to Domino (IBM presentation) - 404 error)

Java 7을 사용하여 Equinox 3.8.2 프로젝트 컴파일 (Compile Equinox 3.8.2 Project with java 7)

OSGI 애플리케이션에서 EntityManager를 제공하는 모범 사례 (Best practice to provide EntityManager in OSGI applications)

Eclipse RCP 제품 파일 - 플랫폼별 종속성이 있는 여러 플랫폼을 처리하는 방법 (Eclipse RCP Product File - how to handle multiple platforms with platform specific dependencies)

OSGI 번들이 설치 및 시작되었지만 출력이 표시되지 않음 (OSGI Bundle Installed and Started but no visible output)

Jetty 서버의 포트(Equinox OSGi) (Port in Jetty server (Equinox OSGi ))

Equinox에서 Arquillian 실행 (Running Arquillian in Equinox)

OSGi 가져오기 버전 제한을 동적으로 설정하시겠습니까? (Setting OSGi import version restrictions dynamically?)

OSGI의 AspectJ LoadTimeWeaving (AspectJ LoadTimeWeaving on OSGI)

user.home 디렉토리에 쓰지 못하도록 Eclipse 위치를 어떻게 수정합니까? (How modify Eclipse locations to prevent write to user.home directory?)







코멘트