I am getting below error when I use (https://github.com/pramoth/specification-with-projection)
Caused By: org.springframework.data.mapping.PropertyReferenceException: No property findOne found for type <Entity class>
any idea why its throwing this exception?
Looks like you are using incorrect Spring Data version.
This library works with the old versions only. The last changes to support new Spring Data were merged, but not still published.
You can try to use the last version from here
https://mvnrepository.com/artifact/th.co.geniustree.springdata.jpa/specification-with-projections
Maybe it will work.
Also I have a fork of the library that supports the last Spring Boot versions and Java 17. It can be temporarily used before the last version of the library will be published
https://github.com/v-ladynev/specification-with-projection-embeded
Related
I just tried to run an OptaPlanner project in Spring Boot, but there's only very simple text in OptaPlanner User Guide for Spring.
Actually, I think it is very easy to copy all domain objects, configuration files and drools files from an OptaPlanner project to Spring Boot project without any changes, but the only question is how to call Solver's solve method.
I made it run after Spring Boot startup with a class (named CommandLineAppStartupRunner) which implements CommandLineRunner interface, and I called solve method in its run method. Finally, I got an exception like follows:
Caused by: java.lang.IllegalArgumentException: Can not set org.optaplanner.core.api.score.buildin.hardmediumsoft.HardMediumSoftScore field springbootcloudbalance.domain.CloudBalance.score to springbootcloudbalance.domain.CloudBalance
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:393)
at org.optaplanner.core.impl.domain.common.accessor.ReflectionFieldMemberAccessor.executeGetter(ReflectionFieldMemberAccessor.java:54)
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.getScore(SolutionDescriptor.java:1071)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.cloneSolution(AbstractScoreDirector.java:212)
at org.optaplanner.core.impl.solver.scope.DefaultSolverScope.setWorkingSolutionFromBestSolution(DefaultSolverScope.java:230)
at org.optaplanner.core.impl.solver.AbstractSolver.solvingStarted(AbstractSolver.java:75)
at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:210)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:190)
at springbootcloudbalance.CommandLineAppStartupRunner.run(CommandLineAppStartupRunner.java:55)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:818)
... 10 common frames omitted
I checked the code, and found the exception throws because the object from field.getDeclaringClass() is a different instance from the one from var1.getClass(). I'm afraid it due to the implementation of java reflection conflicts between OptaPlanner and Spring Boot.
The version I used is as follows:
OptaPlanner 7.11.0.Final
Spring Boot 2.0.5.RELEASE
JVM 1.8.0_181
Removing the spring-boot-devtools dependency fixes this error. Another SO question similar to this one explains it has something to do with different classloaders: Optaplanner's Drools working memory is empty. The accepted answer also mentions a possible fix:
To fix it, configure spring dev tools to load Drools libraries in the RestartClassLoader, together with the project's classes: using-boot-devtools-customizing-classload
Nick's answer is correct. This is just to figure out what's going on.
This line means that optaplanner is extracting CloudBalance.getScore():
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.getScore(SolutionDescriptor.java:1071)
This line means that it's using a ReflectionFieldMemberAccessor for that, which is just way to read a field through reflection (including private fields):
at org.optaplanner.core.impl.domain.common.accessor.ReflectionFieldMemberAccessor.executeGetter(ReflectionFieldMemberAccessor.java:54)
Now the error message is where it gets interesting:
Can not set ...HardMediumSoftScore field ...CloudBalance.score to ...CloudBalance
It looks like basically doing:
CloudBalance cloudBalance2 = cloudBalance.getScore();
Huh?
Musa provided this answer, but someone deleted it, despite that the JIRA link is extremely relevant, as it points out which version of OptaPlanner will deal better with this problem:
"An issue was submitted to OptaPlanner to provide better error messages for such cases: https://issues.jboss.org/browse/PLANNER-1586. Feel free to add any comments or suggestions."
I've upgraded my application to use Spring Core version 5.0.8 (previously it was using version 4.3.6).
My app uses Postgresql 10.4 with JDBC driver version 42.2.5 and C3p0 version 0.9.5.2.
After the Spring Core upgrade, the application started throwing the following exception when trying to set the value of a CLOB column:
Method org.postgresql.jdbc.PgPreparedStatement.setClob(int, Reader, long) is not yet implemented.; nested exception is java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgPreparedStatement.setClob(int, Reader, long) is not yet implemented
I saw that the method setValue of spring class org.springframework.jdbc.core.StatementCreatorUtils changed on latest versions and now it is not catching the exception SQLFeatureNotSupportedException and using a fallback method anymore, as it did on previous versions.
I've seen several answers related to workarounds when using JPA/Hibernate but it is not my case, the application does not use Hibernate at all.
What could I do to solve this issue? Any help is really appreciated.
Thanks,
Mariana
So I am following https://spring.io/guides/gs/accessing-twitter/ to connect my application to Twitter to get some user data. But it looks like with recent changes to Spring boot (version 2.0.3.RELEASE) and Spring-social-twitter, I am not able to execute the said article successfully. I keep getting following error:
Consider defining a bean of type 'org.springframework.social.twitter.api.Twitter' in your configuration.
Has anyone tried the same sample with new Spring boot release? What am I missing?
I am having some trouble trying to run an in-memory hive while writing tests for a dropwizard swagger app. I have tried both hiverunner and hiveqlunit.
There are 2 types of tests. One is for testing dropwizard/swagger API endpoints using dropwizard integration testing (no need for hive here) and the other is for testing the hive integration where I need to hit the api and setup an in-memory hive to query and verify data is stored in hiveDB (psql).
The two in-memory hive dependencies (Note that I am using one at a time) always have some kind of conflict with the existing dropwizard and swagger dependencies. I am guessing it has something to do with jersey but I've tried a lot of things and still no luck.
I can run in-memory hive just fine and do all CRUD if I am not hitting the dropwizard/swagger api. But I just can't get the two services to play along at the moment.
Versions in Maven:
io.dropwizard:dropwizard-core version: 0.9.2
com.smoketurner:dropwizard-swagger version: 0.9.2-3
com.facebook.presto.hive:hive-apache-jdbc version: 0.13.1-3
com.klarna:hiverunner version: 3.0.0
OR
org.finra.hiveqlunit:hiveQLUnit version: 1.0
dropwizard-swagger uses org.reflections:reflections:jar:0.9.10 and com.klarna:hiverunner uses org.reflections:reflections:jar:0.9.8.
When I didn't exclude anything, I got the following:
java.lang.NoSuchMethodError: org.reflections.util.ClasspathHelper.forPackage(Ljava/lang/String;[Ljava/lang/ClassLoader;)Ljava/util/Collection;
So I tried excluding org.reflections:reflections from hiverunner and I got the 3 Exceptions:
java.lang.RuntimeException: javax.servlet.ServletException: io.dropwizard.jersey.setup.JerseyServletContainer-73437222#8a344094==io.dropwizard.jersey.setup.JerseyServletContainer,1,false
Caused by: A MultiException has 3 exceptions. They are:
1. java.lang.NullPointerException
2. java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
3. java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
Then I tried excluding org.reflections:reflections from dropwizard-swagger and added a separate dependency for org.reflections:reflections by adding the following dependency to my pom.xml:
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
</dependency>
And got the following:
java.lang.NoClassDefFoundError: com/google/common/base/MoreObjects
So I added the latest guava (version 20.0) and then it gives me another error. This seems like dependency hell.
Has anyone ever encountered this problem before? It seems like dropwizard and hiverunner do not play along well. Maybe it has to do with the versioning of jersey 1 & 2.
I got some other error regarding jackson-databind, so I did some research and found out I had to have the same version for the following dependencies:
com.fasterxml.jackson.core:jackson-databind (from `dropwizard`)
com.fasterxml.jackson.module:jackson-module-scala (from `hiverunner/hiveqlunit`)
And now I am back to the previous 3 Exceptions...
Any help will be appreciated.
Edit: Found out that hiveqlunit is using the following:
com.sun.jersey:jersey-server:jar:1.9
Which is one of the last versions before moving to the following maven dependency:
org.glassfish.jersey.core:jersey-server
It is having conflicts with dropwizard's org.glassfish.jersey.core:jersey-server:jar:2.22.
How can i resolve this conflict?
This is a Maven project with Hibernate Search. The Servlet works perfectly on Wildfly 9.
As soon as I start it on Wildfly 10, I get a crash when Spring autowires the beans:
ERROR [ContextLoader]:351 - Context initialization failed
nested exception is java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.search.hcore.impl.HibernateSearchIntegrator not a subtype
[...]
Caused by: java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.search.hcore.impl.HibernateSearchIntegrator not a subtype
at java.util.ServiceLoader.fail(ServiceLoader.java:239)
at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:341)
at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:57)
at org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:247)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:73)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1915)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
I tried different version of the declared libraries without success.
<spring.version>4.2.6.RELEASE</spring.version>
<spring.boot.version>1.3.5.RELEASE</spring.boot.version>
<lucene.version>4.10.4</lucene.version>
<hibernate-search-orm.version>5.3.0.Final</hibernate-search-orm.version>
<solr-core.version>4.10.4</solr-core.version>
Anyone have any idea of what's going on?
Both Hibernate ORM and Hibernate Search are included in WildFly since version 8.
A notable difference in WildFly 10 compared to WildFly 9 is that Hibernate Search will be automatically added to your classpath if its usage is being detected. This will make your WAR files smaller and use the latest stable versions so it's the approach I'd recommend (although I'm not a Spring user - would love to hear if it makes things harder for Spring users, please let me know on the Hibernate forums.)
The detection rule is triggered if both:
You are using Hibernate as your persistence provider implementation
Any of your entities are annotated with #Indexed
So I suspect your best solution is to make sure that you're not including neither Hibernate ORM nor Hibernate Search in your deployment to avoid conflicts.
If you rather prefer to use your own version of the frameworks you can set the following property to either not inject these dependencies (so to use the libraries that you bundle in your application), or you can also choose to package custom versions of these in WildFly modules and use the alternative version (you can have alternative versions with a different "slot" identifier).
wildfly.jpa.hibernate.search.module = none
This property needs to be defined in your persistence.xml.
See also the WildFly 10 JPA Reference Guide for a full description of this and similar properties.