0

When I hit the API from postman, Data needs to be fetched from Mongodb but it's not able to fetch the records from mongodb via hibernate ogm since it's showing error as syntax error in query hibenrateExpection via jar file. but when I try to run it in eclipse, it's able to fetch the records from mongodb. Could someone experienced this issue?

plugins {
    id 'org.springframework.boot' version '2.2.6.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}
apply plugin: 'java'
apply plugin: 'eclipse'

group = 'com.local.java.programs'
version = '0.0.1'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    // implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'  
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'io.projectreactor:reactor-test'
    
    // https://mvnrepository.com/artifact/org.hibernate.ogm/hibernate-ogm-mongodb
    compile group: 'org.hibernate.ogm', name: 'hibernate-ogm-mongodb', version: '5.4.1.Final'
    // https://mvnrepository.com/artifact/org.hibernate/hibernate-core
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.16.Final'
    
    compile('org.springframework.boot:spring-boot-starter-log4j2')    
    compile'org.springframework.boot:spring-boot-starter-data-mongodb'
    compile 'org.springframework.boot:spring-boot-starter-security'
    compile 'org.springframework.boot:spring-boot-starter-mail'
    // https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
    compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
    // https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
        
    // https://mvnrepository.com/artifact/org.springframework/spring-webflux
    compile group: 'org.springframework', name: 'spring-webflux'
    // https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.12'
    // https://mvnrepository.com/artifact/io.projectreactor/reactor-test
    testCompile group: 'io.projectreactor', name: 'reactor-test', version: '3.3.5.RELEASE'
    // https://mvnrepository.com/artifact/org.json/json
    compile group: 'org.json', name: 'json', version: '20200518'
}

test {
    useJUnitPlatform()
}
Viswa
  • 45
  • 1
  • 2
  • 9
  • It's hard to help you if you don't show the exception nor the query that it's giving you issues. There is probably something different between the dependencies you are using with Eclipse and the one you are using when the app is deployed – Davide D'Alto Oct 01 '20 at 03:57
  • Query, I'm using => "SELECT c FROM Product c WHERE c.product_id =:pid ORDER BY c._id DESC" Exception, I'm getting syntax error in query Caused by: syntax error in query: caused by: Product is not mapping caused by: Product is not mapping But I have given the Classname as Product with @entity annotation - javax.persistence.Entity Adding build.gradle dependencies above – Viswa Oct 06 '20 at 19:11
  • I'm not familiar with Postman, what's happening is that Hibernate cannot find the Product class on the classpath and so it doesn't see it as an entity. You need to make sure that everything in the right place and it's probably a good idea to add the entity to the configuration explicitly. This page contains a lot of info: https://thorben-janssen.com/jpa-persistence-xml/#Include_one_or_more_specific_managed_classes – Davide D'Alto Oct 09 '20 at 08:24
  • yes you are right. If I set entity class manually in persistence.xml file, I'm not facing this issue but when I build with gradle I'm facing this issue. same problem in gradle build on below link and I'm new to gradle. I was used maven earlier and I have not faced this problem. https://stackoverflow.com/questions/51353433/how-should-i-build-my-java-code-using-hibernatejpa-with-gradle. @Davide – Viswa Oct 09 '20 at 18:28

0 Answers0