I am trying to execute some Java with the Maven exec plugin, and am getting an error Caused by: org.hibernate.UnknownEntityTypeException: Unable to locate persister: my.biz.CoolEntity. I tried a number of failed solutions, before ultimately finding a hacky fix. Based on the hacky fix, I believe the issue to be a runtime classpath error.
I am looking for an answer that will tell me how to address the problem without resorting to copying the needed files into place, as I do in the hacky fix.
Background
I have a Maven project "Project A" which has dependencies upon Hibernate 5.0.1.Final as well as another project "Project B". Project B contains my JPA entity classes, including my.biz.CoolEntity.
Normally, I build everything into a shaded JAR and run/deploy that, without any issues.
Hibernate issue
Recently, I began using Maven's exec:java goal, but am running into what on the surface is a Hibernate issue. when I run mvn exec:java -DmainClass=my.biz.CoolEntity, I get this error:
Caused by: org.hibernate.UnknownEntityTypeException: Unable to locate persister: my.biz.CoolEntity
at org.hibernate.internal.SessionFactoryImpl.locateEntityPersister(SessionFactoryImpl.java:792) ~[hibernate-core-5.0.1.Fi
nal.jar:5.0.1.Final]
at org.hibernate.internal.SessionImpl.locateEntityPersister(SessionImpl.java:2641) ~[hibernate-core-5.0.1.Final.jar:5.0.1
.Final]
at org.hibernate.internal.SessionImpl.access$2500(SessionImpl.java:164) ~[hibernate-core-5.0.1.Final.jar:5.0.1.Final]
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.<init>(SessionImpl.java:2579) ~[hibernate-core-5.0.1.Final
.jar:5.0.1.Final]
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.<init>(SessionImpl.java:2566) ~[hibernate-core-5.0.1.Final
.jar:5.0.1.Final]
at org.hibernate.internal.SessionImpl.byId(SessionImpl.java:1044) ~[hibernate-core-5.0.1.Final.jar:5.0.1.Final]
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955) ~[hibernate-core-5.0.1.Final.jar:5.0.1.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1075) ~[hibernate-entitymanager-5.
0.1.Final.jar:5.0.1.Final]
Failed attempts
I tried making use of the exec plugin's <additionalClasspathElements> and <includePluginDependencies>. The first solution didn't result in any different, and the second resulted in a compile-time error.
Hacky fix
What ended up working for me was copying the compiled classes from Project B into Project A.
Try changing the imports from "javax" to "jakarta". I had the same issue and mine worked when I made the change.
When the entities are residing in a different jar, you have to include it in persistence.xml. <jar-file>entities-packaged.jar</jar-file>. Different options are explained here
When we use Hibernate 5 jars, then we get
org.hibernate.UnknownEntityTypeException: Unable to locate persister".
I just changed the hibernate jar versions from 5 to 4 and then everything was fine.
Hibernate 5 does not locate the entity classes even after mapping.
I too got the same exception and it was due to missing the entity annotation #Entity for the class. Please check if the #Entity annotation is available in your class
Related
I am getting this error message when I try to compile my new modularized Java 11 application:
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\inter\.m2\repository\xalan\xalan\2.7.2\xalan-2.7.2.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.apache.bsf.BSFManager not in module
This appears to be an issue from a dependency of a dependency. I can't even find which module is pulling it in so I can update it.
I am using openjdk 11.0.2, IntelliJ 2018.3.4, Maven
Any advice how I can troubleshoot or fix this? I have found very little documentation on this issue.
Xalan
I had a look at their bug tracker following their index page and wasn't able to find this reported and not sure how actively is the library being maintained either.
General Explanation
Just to explain what has caused the issue in your code, I would share a screenshot and then try to add details around it.
So within the JAR that for version 2.7.2, there are service declarations (META-INF/services) which include org.apache.xalan.extensions.bsf.BSFManager as one of them. The service file here has to indicate the Provider thereby for itself and the class is supposed to be present on the modulepath to be resolved for reliable configuration of modules.
In this case for the module xalan(automatic module), the service listed doesn't have the provider class packaged within the dependency itself. (See the package org.apache, it doesn't further have package bsf and the class BSFManager thereby. Hence the exception as you get.
Short term hack
One of the tweaks to get that resolved would be to get update the library jar (patch it) and get rid of the service file if you're not using it. Or to add the provider copied from the corresponding artifact.
If you don't directly depend on this artifact or its parent dependencies, you can let those remain on the --classpath and get resolved as an unnamed module for your application.
Long term solve
An ideal way would be to report this to the maintainers and getting it resolved. It depends though on how actively are they maintaining it e.g. the last release for xalan was almost 5 years back, might just want to look for an actively participated alternative in my opinion.
I tried to install update for TestNG in eclipse:
"Help -> Check for updates -> deselect all and select TestNG check box. Then
install latest version i installed the version which starts with 7.2.0.
It fixed the issue for me.
I use eclipse for my optaplanner project development and I am able to execute my code from eclipse without any problem. To make this project as an executable, I exported it as a jar file using eclipse export wizard.
Then I run my jar from terminal using the command java -jar myOptaPlanner.jar, then, I get below error
WARN given scan urls are empty. set urls in the configuration
Exception in thread "main" java.lang.IllegalStateException: The scanAnnotatedClasses
(ScanAnnotatedClassesConfig()) did not find any classes with a PlanningSolution
annotation.
Maybe you forgot to annotate a class with a PlanningSolution annotation.
Maybe you're using special classloading mechanisms (OSGi, ...) and this is a bug.
If you can confirm that, report it to our issue tracker and workaround it by
defining the classes explicitly in the solver configuration.
at org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.loadSolutionClass(ScanAnnotatedClassesConfig.java:106)
at org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.buildSolutionDescriptor(ScanAnnotatedClassesConfig.java:86)
at org.optaplanner.core.config.solver.SolverConfig.buildSolutionDescriptor(SolverConfig.java:270)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:216)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:57)
at org.roster.app.WorkerRosteringApp.main(WorkerRosteringApp.java:36)
Is this really a bug or am I exporting it wrong?
Update: I tried to export jar using maven-shade-plugin and here also I am getting the same error.
Thanks
scanAnnotatedClasses doesn't seem to work in a jar file. Instead, use following workaround:
<solutionClass>path.to.your.SolutionClass</solutionClass>
<entityClass>path.to.your.EntityClassI</entityClass>
<entityClass>path.to.your.EntityClassII</entityClass>
and delete the scanAnnotatedClasses in your config file.
If you don't want to declare the solution and entity classes manually, including the packages containing the solution and entity classes also works as workaround:
<scanAnnotatedClasses>
<packageInclude>your.package.here</packageInclude>
</scanAnnotatedClasses>
Documentation about <packageInclude> can be found here
I haven't looked at my Eclipse plugin project for a few weeks, but after I updated to Neon.1, I noticed the following error in the Problems view:
Checkstyle execution failed due to an internal error. Please check the error log for details.
In the error log, I saw things like this:
!MESSAGE Checkstyle-Plugin: cannot initialize module TreeWalker - Unable to instantiate
'com.github.sevntu.checkstyle.checks.coding.ForbidCertainImportsCheck' class,
it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotation.com.github.sevntu.checkstyle.checks.coding.ForbidCertainImportsCheck,
com.puppycrawl.tools.checkstyle.checks.blocks.com.github.sevntu.checkstyle.checks.coding.ForbidCertainImportsCheck,
[deleted numerous similar class names],
com.puppycrawl.tools.checkstyle.com.github.sevntu.checkstyle.checks.coding.ForbidCertainImportsCheckCheck.
Please recheck that class name is specified as canonical name or read how to configure short
name usage http://checkstyle.sourceforge.net/config.html#Packages. Please also
recheck that provided ClassLoader to Checker is configured correctly.
After I saw this in my neon.1 workspace, I also noticed that my older workspace running in Mars.2 was also showing the same problem.
I've managed to resolve this.
The parent POM of the project I work on had a change to its checkstyle configuration, and it now requires adding the "seventu" auxiliary checkstyle plugin, which I found at https://github.com/sevntu-checkstyle/sevntu.checkstyle . Once I installed that (and did the usual "Maven Update Projects" invocation), the errors went away.
I am attempting to follow the Language and File Type tutorial for JetBrains IntelliJ
It worked, once. Now (whatever I do) I receive an assertion failure stating that it was expecting an instance of FileTypeFactory and got my SimpleFileTypeFactory
My public class SimpleFileTypeFactory extends com.intellij.openapi.fileTypes.FileTypeFactory so I'm not sure how to react to this ...
Caused by: java.lang.AssertionError: Expected: class com.intellij.openapi.fileTypes.FileTypeFactory; Actual: class bengie.idea.SimpleFileTypeFactory
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.assertClass(ExtensionPointImpl.java:408)
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapters(ExtensionPointImpl.java:242)
at com.intellij.openapi.extensions.impl.ExtensionPointImpl.getExtensions(ExtensionPointImpl.java:185)
... especially when Google has no matches for "Expected: class com.intellij.openapi.fileTypes.FileTypeFactory; Actual"
Has anyone resolved this sort of thing?
I was depending on a Maven module (actually, two of them) The rest of my project is built with Maven so it seemed logical and looked like it would work. I didn't remember the build seizing up when I added them, so I had forgotten about it. Removing the dependency, starting a debug session, uninstalling the plugin, rinse, repeat and I eventually stopped seeing error messages.
I've since stuffed the maven modules into a jar-with-dependencies and told the IntelliJ plugin module to load the resulting .jar No problems so far - Yay!
I have a dependency resolution issue with another plugin, which is causing the following error:
Caused by: java.lang.IncompatibleClassChangeError
at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.init(MailMessageContentRenderer.groovy:125)
at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.with(MailMessageContentRenderer.groovy:158)
at grails.plugin.mail.MailMessageContentRenderer.render(MailMessageContentRenderer.groovy:47)
at grails.plugin.mail.MailMessageBuilder.doRender(MailMessageBuilder.groovy:235)
at grails.plugin.mail.MailMessageBuilder.html(MailMessageBuilder.groovy:253)
The way to recreate the error:
Install jaxrs 0.7 plugin and its dependencies in build config: spock 0.7 and org.springframework:spring-test:3.1.2.RELEASE
When I do run-app, since everything is loaded directly from resources, there is no error. However, doing a run-war, as dependencies are resolved I get the the above error.
The mail plugin depends on org.springframework:spring-test:3.1.0.RELEASE which gets kicked out. So, probably that is the reason.
Any suggestions on how to deal with this issue? I don't necessarily want to recompile the plugin separately as it becomes hard to maintain. I already tried a lot of combination in buildconfig for exclusion, but doesn't seem to work.
Thanks.