question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JBoss throws ClassCastException: org.hibernate.annotations.common.reflection.java.JavaXProperty cannot be cast to org.hibernate.annotations.common.reflection.XProperty

See original GitHub issue

Hi there! I’m trying to use your types but when I build it I get this exception:

msc.service.StartException in service jboss.persistenceunit."server-api.war#dgo": javax.persistence.PersistenceException: [PersistenceUnit: db-test] Unable to build Hibernate SessionFactory server-api_1 | at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:179) server-api_1 | at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:121) server-api_1 | at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667) server-api_1 | at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:193) server-api_1 | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) server-api_1 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) server-api_1 | at java.lang.Thread.run(Thread.java:748) server-api_1 | at org.jboss.threads.JBossThread.run(JBossThread.java:320) server-api_1 | Caused by: javax.persistence.PersistenceException: [PersistenceUnit: dgo] Unable to build Hibernate SessionFactory server-api_1 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) server-api_1 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) server-api_1 | at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) server-api_1 | at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:161) server-api_1 | ... 7 more server-api_1 | Caused by: org.hibernate.MappingException: Could not instantiate Type: com.vladmihalcea.hibernate.type.json.JsonBinaryType server-api_1 | at org.hibernate.type.TypeFactory.type(TypeFactory.java:139) server-api_1 | at org.hibernate.type.TypeFactory.byClass(TypeFactory.java:109) server-api_1 | at org.hibernate.type.TypeResolver.heuristicType(TypeResolver.java:112) server-api_1 | at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:416) server-api_1 | at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:398) server-api_1 | at org.hibernate.mapping.Property.isValid(Property.java:225) server-api_1 | at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:595) server-api_1 | at org.hibernate.mapping.RootClass.validate(RootClass.java:265) server-api_1 | at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329) server-api_1 | at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443) server-api_1 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) server-api_1 | ... 9 more server-api_1 | Caused by: java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaXProperty cannot be cast to org.hibernate.annotations.common.reflection.XProperty server-api_1 | at com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor.setParameterValues(JsonTypeDescriptor.java:58) server-api_1 | at com.vladmihalcea.hibernate.type.json.JsonBinaryType.setParameterValues(JsonBinaryType.java:66) server-api_1 | at org.hibernate.type.TypeFactory.injectParameters(TypeFactory.java:152) server-api_1 | at org.hibernate.type.TypeFactory.type(TypeFactory.java:135) server-api_1 | ... 19 more

Not sure it’s a bug on your lib or something I’m missing, any help? Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
vpriscancommented, Mar 12, 2020

@vladmihalcea @TMSantos @oisti @cec Okay I solved it.

  1. For hibernate-commons-annotations dependency, use provided scope if you are using Maven, or compileOnly configuration if you are using Gradle. You can also just remove that dependency declaration altogether, because you probably don’t need it for compilation. Example for Maven:
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>5.0.5.Final</version>
            <scope>provided</scope>
        </dependency>
  1. Explicitly add org.hibernate.commons-annotations module to Dependencies in your MANIFEST.MF:
Dependencies: org.hibernate.commons-annotations

You can make Maven add that for you, for example using the maven-ejb-plugin if you use ejb packaging:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Dependencies>
                                org.hibernate.commons-annotations
                            </Dependencies>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

For some reason org.hibernate.commons-annotations behaves like a “private” jboss module, requiring an explicit module dependency to it, although its module.xml does not set jboss.api property to private.

1reaction
lennertdefeytercommented, Jun 4, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot be cast to org.hibernate.annotations.common.reflection ...
JavaReflectionManager cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector. when I used hibernate ...
Read more >
Hibernate Error : JavaReflectionManager cannot be cast to ...
Caused by: java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaReflectionManager cannot be cast to ...
Read more >
org.hibernate.ejb...| JBoss.org Content Archive (Read Only)
java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider.
Read more >
org.hibernate.annotations.common.reflection.java ...
org.hibernate.annotations.common.reflection.java.JavaReflectionManager maven / gradle build tool code. The class is part of the package ➦ Group: ...
Read more >
org.hibernate.annotations.common.reflection.XProperty java ...
Best Java code snippets using org.hibernate.annotations.common.reflection. ... public XClass getPropertyClass() throws MappingException { if ( property.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found