spring data for mongo Caused by: java.lang.AbstractMethodError - spring

i use spring data to jpa and mongo.
dependency:
spring version is 4.0.2.RELEASE
spring-data-jpa version is 1.4.3.RELEASE
spring-data-mongodb version is 1.2.0.RELEASE
xml config:
<context:component-scan base-package="develop" />
<jpa:repositories base-package="develop.erp"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager" />
<mongo:repositories base-package="develop.doc" />
model:
#Document
public class OrderItem extends AbstractDocument {
enter code here
#Id
private BigInteger id;
private Integer orderNumber;
public get and set method ...
}
public interface IOrderItemDao extends PagingAndSortingRepository<OrderItem, BigInteger> {
List<OrderItem> findByOrderNumber(Integer number);
}
exception :
Caused by: java.lang.AbstractMethodError
at org.springframework.data.repository.query.Parameters.getBindableParameters(Parameters.java:235)
at org.springframework.data.repository.query.Parameters.assertEitherAllParamAnnotatedOrNone(Parameters.java:262)
at org.springframework.data.repository.query.Parameters.<init>(Parameters.java:85)
at org.springframework.data.mongodb.repository.query.MongoParameters.<init>(MongoParameters.java:47)
at org.springframework.data.mongodb.repository.query.MongoQueryMethod.createParameters(MongoQueryMethod.java:76)
at org.springframework.data.repository.query.QueryMethod.<init>(QueryMethod.java:70)
at org.springframework.data.mongodb.repository.query.MongoQueryMethod.<init>(MongoQueryMethod.java:62)
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory$MongoQueryLookupStrategy.resolveQuery(MongoRepositoryFactory.java:119)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:162)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:44)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:144)
can someone have any idea ?
thanks very much..

In my case I had spring-data-solr(2.0.1) and spring-data-jpa(1.9.1) in my project. I noticed SolrQueryLookupStrategy was implementing QueryLookupStrategy interface from spring-data-commons which was transitively taken from spring-data-jpa jar. The problem was new solr was not compatible with old spring-data-jpa - signature of method in QueryLookupStrategy changed and code was not compiled correctly. Bumping spring-data-jpa to 1.10.1 solved the issue. I assume you have a similar problem. Track down where exception is thrown and search for compilation problems in spring jars.

This is due to incompatible version of spring-data and db-driver dependency. Please check if the version of db-driver is compatible with the provided spring-data dependency. I was facing the same issue, resolved by bumping the version of 'spring-data'.

Related

Hibernate Unknow Entity Exception after Spring/Hibernate Upgrade

I did Spring upgrade from 3.x to 5.x and even Hibernate i got it upgraded to 5.x. Previously i was able to execute all the nativequeries using Hibernate JPA, but now the same piece of code is not working especially component-scan annotation (not instantiating beans anymore) after upgrade.
Below are the code snippets.
In Application context:
<context:component-scan base-package="com.flight.nh.domain" />
Bean class in com.flight.nh.domain package.
#Entity
#Table(name = "NOTIFICATION_ROLE")
public class NotificationRole implements Serializable {
}
Piece of code were below exception is thrown:
Caused by: org.hibernate.MappingException: Unknown entity: com.baxter.renal.nh.domain.NotificationRole
at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(MetamodelImpl.java:670) ~[hibernate-core-5.3.14.Final.jar:?]
Query query = this.entityManager.createNativeQuery(nativeSql.toString(), NotificationRole.class);
query.setParameter(INITIAL_VERSION, INITIAL_VERSION_VAL);
query.setParameter(USER_ID, userId);
query.setParameter(ROLE_LIST, roleIdList);
return query.getResultList();
Looks like NotificationRole bean could not be instantiated by spring leading to the exception as component-scan is not working as expected.
The same piece of code used to work with Spring 3.x. Can anyone please suggest how to proceed.

Can't made changes on synonym using spring

I created a synonym called CLASSE_SYN with oracle.
Using Spring, I do like that:
#Entity
#Table(name = "CLASSE_SYN")
public class Classe implements Serializable {}
and I add on persistence.xml:
<property name="hibernate.synonyms" value="true"/>
But I can't made changes on that synonym from spring code source.
Have you please any idea about solving that issue ?.
Try upgrade your hibernate version.
Hibernate 4.3.0 supports your need.
HTH.

Spring Boot JPA CrudRepository

I'm working with Spring Boot + Spring Data JPA and facing this problem when trying to inject a class that extends CrudRepository:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'topicRepository': Could not resolve
matching constructor (hint: specify index/type/name arguments for
simple parameters to avoid type ambiguities)
Repository Class:
public interface TopicRepository extends CrudRepository<Topic, Integer> {}
Service Class:
#Service
public class TopicService {
#Autowired
private TopicRepository topicRepository;
}
Any suggestions?
I was having the same issue, and I fixed it by switching Spring Boot versions. Changing the Spring Data JPA versions did nothing (this is where I assumed the bug would be), so I think there is a bug in Spring Boot version 1.5.1. I switched back to version 1.4.3 and the error was gone. I didn't try subsequent/different versions, so you may just have to experiment with your dependencies and their versions.
For the record, you can have your service class annotated with #Repository, it shouldn't make any difference. I've been setting these apps up the same way using the service/dao pattern, and it has never been too picky with the annotations. Hopefully this may help others whose Spring Boot development flow suddenly throws an error!
Which versions of spring-data-commons and spring-data-jpa are you using. I just ran into this using spring-data-commons 1.13.x with spring-data-jpa 1.10.x. Upgrading spring-data-jpa to 1.11.x fixed the issue for me.
I too had the same issue after updating Spring Boot to 1.5.4.
I am also using spring-data-envers, which was at version 1.0.4. Upgrading to 1.4.1 solved the problem.
I hope it helps someone :)
Make sure:
1) TopicRepository is annotated with #Repository.
2) You have the scanning packages configured:
<jpa:repositories base-package="mypkg.repositories"></jpa:repositories>
Had the same issue on 1.5.2. Upgrading to 1.5.5 solved the problem.
You can use Applicationcontext to inject repository to this reference topicRepository..
You just declare applicationcontext in #rest controller class
Same like topicRepository by using annotation. Then you pass this to the service class which should take parms through constructor.
Ex-
public TopicService(Applicationcontext ctx) {this.topicRepository =context.getBean(TopicRepository.class);
}

jpa 2.1 spring boot with web sphere 8.5.5.8(full version) jdk 7

i followed the approach suggested by jeff
https://gist.github.com/jeffsheets/aec3e94870ef903ce7efe33e00563d3c
I was able to overcome the jpa 2.1 java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider.
But i get the following error A servlet named com.x...JerseyConfig can not be dynamically added because a servlet configuration with the same name already exists. i am using WebSphere 8.5.5.8 Full version with JDK 1.7 spring boot 1.4.0.M3.
In my JerseyConfig.java
#Component
#PropertySources(value = {
#PropertySource("classpath:application.properties"),
#PropertySource("classpath:ValidationMessages.properties")})
#DependsOn("hibernatePersistenceProviderResolver")
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
packages("com.x.package");
}
}
Thanks for any hints or pointers.
I did the following to make it work (in addition to #DependsOn mentioned previously).
1) load local class loader first and parent last.
2) Add the JVM property at the WebSphere Appserver com.ibm.websphere.jaxrs.server.DisableIBMJAXRSEngine to true in order to use only the JAX RS shipped with the application. (which fixes the servlet name already exists).
3) After deploying successfully when i ran my REST endpoint i got the following error at run time.
UOWManager transaction processing failed; nested exception is com.ibm.wsspi.uow.UOWException: java.lang.VerifyError: com/ibm/websphere/uow/UOWSynchronizationRegistry.registerInterposedSynch ronizat ion(Ljavax/transaction/Synchronization)V
To fix this add spring.jta.enabled=false to use the WebShpere JTA. (Ideally prefer to override web sphere JTA and use spring JTA, need to figure out a way).

drools-6 (kie) auto scanning (from spring) of modules and sessions from kie workbench deployed artifacts

I am trying to build a web (spring-mvc) application with kie (drools 6) integrated via injection. I have used kie workbench to create a workflow, complied and deployed. I have added reference of this artifact in my project's pom.xml and added the local kie-workbench repository as per this blog post and it's working fine (pulling in the artifact as dependency in my maven/spring project). What I am trying to do is inject the kiesession in one of my service as dependency with following snippet -
#Service
public class TniServiceImpl implements TniService {
#Inject
#KSession("tniSession")
private KieSession tniSession;
...
}
In my root-context.xml, I have added the kie namespace as well along with reference to xsd. I have added org.kie.spring.KModuleBeanFactoryPostProcessor as well as per drools documentation. I am trying to make CDI injection work for KSession scanning and injection (it's already working for my other components in same project, using #Inject). So far I am always getting "No qualifying bean of type [org.kie.api.runtime.KieSession] found for dependency" error. Looks like spring is not able to scan the available kie modules and sessions therein. Need help on following -
Is CDI inject really supported with spring? Do I have to configure kmodules and kession explicitly as mentioned here?
Am I missing something here which should make this scanning and injection work?
My environment is following -
spring 3.2.6-RELEASE (including webmvc and other components)
kie-api-6.0.1.FINAL
kie-spring-6.0.1.FINAL
kie-internal-6.0.1.FINAL
I have already gone through following links but no luck (mostly they are not trying to do what I am) -
Loading Drools/KIE Workbench artifacts directly from the repository
why does loading Drools 6 KIE JAR into code fail?
I'll appreciate if anybody can guide me on what could be the missing piece here or if there's no option but to explicitly define all kmodules/ksessions in spring config file.
I had the same problem and found a solution here: http://drools.46999.n3.nabble.com/Spring-4-0-amp-Drools-6-0-1-Integration-issue-td4028052.html
Basically you will need to inject ApplicationContext instead of kieSession and get xml bean manually.
TniServiceImpl.java
#Service
public class TniServiceImpl implements TniService {
#Inject
ApplicationContext context;
KieSession kieSession;
#PostConstruct
public void postConstruct(){
kieSession = (KieSession) context.getBean("ksession1");
}
...
}
root-context.xml
<kie:kmodule id="kmodule1">
<kie:kbase name="kbase1">
<kie:ksession name="ksession1" />
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor" />
Hope this helps.
UPDATE:
Another way to achieve this is to keep xml identical and instead of trying to inject KieSession, inject KieBase. Then, with the instance of KieBase, create new KieSessions.
#Service
public class TniServiceImpl implements TniService {
#Autowired
private KieBase kbase;
/* inside some method */
#RequestMapping(method=RequestMethod.GET)
public #ResponseBody Data getData() {
KieSession ksession = kbase.newKieSession();
...
}
}
The above answer doesn't work with spring mvc. I found that this is a bug in the existing drools and they are fixing it in the next version. I am stuck at this point since I am using DROOLS in batch mode but I want it to be used in a REST Service hosted on websphere.
The above solution works perfectly within a batch program.
This is what I have working with the latest Spring MVC (Spring Boot)
#SpringBootApplication
public class DroolDemoApplication {
public static void main(String[] args) {
SpringApplication.run(DroolDemoApplication.class, args);
}
#Bean
public KieContainer kieContainer() {
return KieServices.Factory.get().getKieClasspathContainer();
}
#Bean
public KieSession kieSession() throws IOException {
return kieContainer().newKieSession("DroolDemoSession");
}
}
and below is the kmodule.xml
<kbase name="DroolDemoKbase" packages="rules">
<ksession name="DroolDemoSession" />
</kbase>
finally all you do in your controller is
#Autowired
private KieSession kieSession;
kieSession.fireAllRules();
hope this helps those folks still having issues
I had similar issues with the rules not being triggered, and I solved it by using the 6.2.0.Final version of the kie-ci and kie-spring. I tried versions: 7.7.0, 7.2.0, 6.5.0 and 6.4.0, but none of them worked.
...
<properties>
<kie.version>6.2.0.Final</kie.version>
</properties>
...
<dependencies>
...
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>${kie.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-spring</artifactId>
<version>${kie.version}</version>
</dependency>
...
</dependencies>
What also helped was running mvn dependency:tree and seeing which versions of which artefacts/projects are being used.

Resources