Reputation: 15
I try to use Hibernate 6.0 in Java 8 with Postgres, but I got this error: Could not access Unsafe class: sun.misc.Unsafe How can I solve it?
org.hibernate.MappingException: Could not instantiate persister
Caused by: java.lang.IllegalArgumentException: Could not create type
at net.bytebuddy/net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:154)
at net.bytebuddy/net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:365)
at net.bytebuddy/net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:174)
at net.bytebuddy/net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:376)
at [email protected]/org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState.load(ByteBuddyState.java:175)
at [email protected]/org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState.loadProxy(ByteBuddyState.java:99)
at [email protected]/org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper.buildProxy(ByteBuddyProxyHelper.java:56)
at [email protected]/org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyFactory.postInstantiate(ByteBuddyProxyFactory.java:61)
at [email protected]/org.hibernate.metamodel.internal.StandardPojoEntityRepresentationStrategy.createProxyFactory(StandardPojoEntityRepresentationStrategy.java:225)
at [email protected]/org.hibernate.metamodel.internal.StandardPojoEntityRepresentationStrategy.<init>(StandardPojoEntityRepresentationStrategy.java:120)
at [email protected]/org.hibernate.metamodel.internal.StandardManagedTypeRepresentationResolver.resolveStrategy(StandardManagedTypeRepresentationResolver.java:54)
at [email protected]/org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:695)
at [email protected]/org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:141)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at [email protected]/org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:97)
... 10 more
Caused by: java.lang.UnsupportedOperationException: Could not access Unsafe class: sun.misc.Unsafe
at net.bytebuddy/net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$Unavailable.initialize(ClassInjector.java:2006)
at net.bytebuddy/net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe.injectRaw(ClassInjector.java:1738)
at net.bytebuddy/net.bytebuddy.dynamic.loading.ClassInjector$AbstractBase.inject(ClassInjector.java:110)
at net.bytebuddy/net.bytebuddy.dynamic.loading.ClassLoadingStrategy$ForUnsafeInjection.load(ClassLoadingStrategy.java:567)
at net.bytebuddy/net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:100)
at net.bytebuddy/net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:6156)
at [email protected]/org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState.lambda$load$0(ByteBuddyState.java:179)
at net.bytebuddy/net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:152)
... ```
Upvotes: 0
Views: 934
Reputation: 16430
You need to add the following command line flag when running the Java process to enable access to the Unsafe class: --add-modules jdk.unsupported
Upvotes: 1