Spring Data Neo4j - Getting an exception when running a cypher query - spring

I'm getting a strange exception when trying to run a simple cypher query. First i'll introduce my code, and then i'll show what cause the exception. So i have the following classes:
A simple class to represent a user profile:
public abstract class Profile extends AbstractEntity {
#Indexed
ProfileType profileType;
#Indexed(indexType = IndexType.FULLTEXT, indexName = "name")
String firstName;
#Indexed(indexType = IndexType.FULLTEXT, indexName = "name")
String lastName;
#Indexed
EyeColor eyeColor;
#Indexed
HairColor hairColor;
#Indexed
Nationality nationality;
#Indexed
int height;
public Profile() {
setProfileType();
}
public Profile(String firstName, String lastName, Nationality nationality, EyeColor eyeColor, HairColor hairColor, int height) {
this();
this.setFirstName(firstName);
this.setLastName(lastName);
this.setNationality(nationality);
this.setHairColor(hairColor);
this.setEyeColor(eyeColor);
this.setHeight(height);
}
/* Getters and Setters */
}
And a simple class, which inherit from Profile, and represents a civilian:
#NodeEntity
public class Civilian extends Profile {
#GraphProperty(propertyType = Long.class)
DateTime dateOfBirth;
#Indexed
boolean missing;
#RelatedTo
#Fetch
Set<Casualty> casualties = new HashSet<Casualty>(); //TODO: design
public Civilian() {
this.profileType = ProfileType.CIVILIAN;
}
public Civilian(String firstName, String lastName, Nationality nationality, EyeColor eyeColor, HairColor hairColor, int height, DateTime dateOfBirth, boolean missing) {
super(firstName, lastName, nationality, eyeColor, hairColor, height);
this.setDateOfBirth(dateOfBirth);
this.setMissing(missing);
}
/* Getters and Setters */
}
So i created the following repository for the Civilian class:
public interface CivilianRepository extends GraphRepository<Civilian> {
#Query("start n=node(*) where n.firstName=~{0} return n")
Page<Civilian> findCiviliansProperties(String firstName, Pageable page);
}
Ok. So i created few Civilian nodes, and populated the graph with them. There are no other nodes in the graph, except for the Civilian nodes. When i run the findCiviliansProperties method, i get the following exception:
Exception in thread "main" org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement start n=node(*) where n.firstName=~{0} return n skip 0 limit 10; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement start n=node(*) where n.firstName=~{0} return n skip 0 limit 10; nested exception is org.neo4j.cypher.EntityNotFoundException: The property 'firstName' does not exist on Node[0]
at org.springframework.data.neo4j.support.query.CypherQueryEngine.query(CypherQueryEngine.java:52)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:98)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:81)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:312)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy33.findCiviliansProperties(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
at com.sun.proxy.$Proxy36.findCiviliansProperties(Unknown Source)
at org.technion.socialrescue.playground.Playground.main(Playground.java:38)
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement start n=node(*) where n.firstName=~{0} return n skip 0 limit 10; nested exception is org.neo4j.cypher.EntityNotFoundException: The property 'firstName' does not exist on Node[0]
at org.springframework.data.neo4j.support.query.CypherQueryEngine.parseAndExecuteQuery(CypherQueryEngine.java:63)
at org.springframework.data.neo4j.support.query.CypherQueryEngine.query(CypherQueryEngine.java:49)
... 20 more
Caused by: org.neo4j.cypher.EntityNotFoundException: The property 'firstName' does not exist on Node[0]
at org.neo4j.cypher.internal.commands.expressions.Property.apply(Property.scala:35)
at org.neo4j.cypher.internal.commands.expressions.Property.apply(Property.scala:29)
at org.neo4j.cypher.internal.commands.RegularExpression.isMatch(Predicate.scala:259)
at org.neo4j.cypher.internal.pipes.FilterPipe$$anonfun$createResults$1.apply(FilterPipe.scala:29)
at org.neo4j.cypher.internal.pipes.FilterPipe$$anonfun$createResults$1.apply(FilterPipe.scala:29)
at scala.collection.Iterator$$anon$22.hasNext(Iterator.scala:390)
at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334)
at scala.collection.Iterator$class.isEmpty(Iterator.scala:272)
at scala.collection.Iterator$$anon$19.isEmpty(Iterator.scala:333)
at org.neo4j.cypher.internal.pipes.SlicePipe.createResults(SlicePipe.scala:32)
at org.neo4j.cypher.internal.pipes.ColumnFilterPipe.createResults(ColumnFilterPipe.scala:37)
at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$6.apply(ExecutionPlanImpl.scala:127)
at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$6.apply(ExecutionPlanImpl.scala:125)
at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl.execute(ExecutionPlanImpl.scala:33)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:59)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:63)
at org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:79)
at org.springframework.data.neo4j.support.query.CypherQueryEngine.parseAndExecuteQuery(CypherQueryEngine.java:61)
... 21 more
Caused by: org.neo4j.graphdb.NotFoundException: 'firstName' property not found for NodeImpl#0.
at org.neo4j.kernel.impl.core.Primitive.newPropertyNotFoundException(Primitive.java:184)
at org.neo4j.kernel.impl.core.Primitive.getProperty(Primitive.java:179)
at org.neo4j.kernel.impl.core.NodeImpl.getProperty(NodeImpl.java:52)
at org.neo4j.kernel.impl.core.NodeProxy.getProperty(NodeProxy.java:155)
at org.neo4j.cypher.internal.commands.expressions.Property.apply(Property.scala:33)
... 38 more
So the most important thing about this exception is the following line - The property 'firstName' does not exist on Node[0].. But how can it be? there are only Civilian nodes in the graph, and they all have the firstName property. Can it be that the neo4j framework adds some more hidden nodes to my graph which i'm not aware of? Because when i change my query into this:
start n=node(*) where has(n.firstName) AND n.firstName=~{0} return n
Everything works fine...
What is wrong?
Thanks!!

neo4j automatically comes with 1 node when you create a new instance, and that's the reference node. You should delete this.
graphDatabaseService.getNodeById(0).delete()

Related

Compilation error using both HashKey and RangeKey in dynamoDB with Springboot

I am using dynamDb with my springboot application. I am trying to save data in the table which has hashKey and sortKey. Initially I tried to annotate my HaskKey and sortKey with #DynamoDBHashKey and #DynamoDBRangeKey respectively. However this was giving me compilation issues. Upon search I found this article https://github.com/derjust/spring-data-dynamodb/wiki/Use-Hash-Range-keys which explains how in springboot we need to create a composite key/id with annotation #id. This id will not be part of the table.
I implemented the same however I still get compilation error:
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eventRepository' defined in com.accuity.kyc.hep.repository.EventRepository defined in #EnableDynamoDBRepositories declared on DynamoDBConfig: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/repository/core/support/ReflectionEntityInformation\r\n\tat org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)\r\n\tat org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)\r\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)\r\n\tat org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)\r\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)\r\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)\r\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)\r\n\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:302)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)\r\n\tat com.accuity.kyc.hep.HepApplication.main(HepApplication.java:16)\r\nCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'historyEventRepository' defined in com.accuity.kyc.hep.repository.HistoryEventRepository defined in #EnableDynamoDBRepositories declared on DynamoDBConfig: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/repository/core/support/ReflectionEntityInformation\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)\r\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)\r\n\tat org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)\r\n\tat org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)\r\n\tat org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)\r\n\t... 19 common frames omitted\r\nCaused by: java.lang.NoClassDefFoundError: org/springframework/data/repository/core/support/ReflectionEntityInformation\r\n\tat java.base/java.lang.ClassLoader.defineClass1(Native Method)\r\n\tat java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)\r\n\tat java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)\r\n\tat java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)\r\n\tat java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)\r\n\tat java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)\r\n\tat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)\r\n\tat java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)\r\n\tat java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)\r\n\tat org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBEntityMetadataSupport.getEntityInformation(DynamoDBEntityMetadataSupport.java:125)\r\n\tat org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactory.getEntityInformation(DynamoDBRepositoryFactory.java:104)\r\n\tat org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactory.getDynamoDBRepository(DynamoDBRepositoryFactory.java:128)\r\n\tat org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactory.getTargetRepository(DynamoDBRepositoryFactory.java:150)\r\n\tat org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:324)\r\n\tat org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:322)\r\n\tat org.springframework.data.util.Lazy.getNullable(Lazy.java:230)\r\n\tat org.springframework.data.util.Lazy.get(Lazy.java:114)\r\n\tat org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:328)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)\r\n\t... 30 common frames omitted\r\nCaused by: java.lang.ClassNotFoundException: org.springframework.data.repository.core.support.ReflectionEntityInformation\r\n\tat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)\r\n\tat java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)\r\n\tat java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)\r\n\t... 50 common frames omitted\r\n"}
My entity class looks like this:
#DynamoDBTable(tableName = "Event")
#NoArgsConstructor
public class Event {
#Id
private EventId eventId;
#DynamoDBHashKey(attributeName = "id")
#DynamoDBAutoGeneratedKey
public String getId() {
return eventId != null ? eventId.getId() : null;
}
public void setId(String id) {
if (eventId == null) {
eventId = new eventId();
}
eventId.setId(id);
}
#DynamoDBRangeKey(attributeName = "eventDate")
public Date getEventDate() {
return eventId != null ? eventId.getEventDate() : null;
}
public void setEventDate(Date eventDate) {
if (eventId == null) {
eventId = new eventId();
}
eventId.setEventDate(eventDate);
}
}
Composite key class:
#NoArgsConstructor
#AllArgsConstructor
public class EventId {
private String id;
private Date eventDate;
#DynamoDBHashKey(attributeName = "id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
#DynamoDBRangeKey(attributeName = "eventDate")
public Date getEventDate() {
return eventDate;
}
public void setEventDate(Date eventDate) {
this.eventDate = eventDate;
}
}
Repository:
#EnableScan
#Repository
public interface EventRepository extends CrudRepository<Event, EventId> {
}
For dependency I am using:
id 'org.springframework.boot' version '2.6.1' and
com.github.derjust:spring-data-dynamodb:5.1.0
I have followed the similar example from couple of other sources. I can not see what am I missing.
Please help.
There is an open issue for this, https://github.com/derjust/spring-data-dynamodb/issues/279. It appears the library is not compatible with Spring Boot 2.2. Per one of the commenters there is a fork available that may support this, but I haven't found this yet.
EDIT: The repository where this supposedly works now is at https://github.com/boostchicken/spring-data-dynamodb.

Spring JPA Repository - Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet

I have a Repository and hitting directly this repository from Postman.
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2115)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1898)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1874)
at org.hibernate.loader.Loader.doQuery(Loader.java:919)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
at org.hibernate.loader.Loader.doList(Loader.java:2610)
at org.hibernate.loader.Loader.doList(Loader.java:2593)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422)
at org.hibernate.loader.Loader.list(Loader.java:2417)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:336)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1980)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:322)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:125)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606)
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:114)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:102)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:92)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 98 common frames omitted
Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=RCON411.PROJECT, DRIVER=4.11.69
at com.ibm.db2.jcc.am.gd.a(gd.java:676)
at com.ibm.db2.jcc.am.gd.a(gd.java:60)
at com.ibm.db2.jcc.am.gd.a(gd.java:127)
at com.ibm.db2.jcc.am.jn.c(jn.java:2561)
at com.ibm.db2.jcc.am.jn.d(jn.java:2549)
at com.ibm.db2.jcc.am.jn.a(jn.java:2025)
at com.ibm.db2.jcc.am.kn.a(kn.java:6836)
at com.ibm.db2.jcc.t4.cb.g(cb.java:140)
at com.ibm.db2.jcc.t4.cb.a(cb.java:40)
at com.ibm.db2.jcc.t4.q.a(q.java:32)
at com.ibm.db2.jcc.t4.rb.i(rb.java:135)
at com.ibm.db2.jcc.am.jn.ib(jn.java:1996)
at com.ibm.db2.jcc.am.kn.sc(kn.java:3058)
at com.ibm.db2.jcc.am.kn.b(kn.java:3841)
at com.ibm.db2.jcc.am.kn.fc(kn.java:702)
at com.ibm.db2.jcc.am.kn.executeQuery(kn.java:672)
at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82)
at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
... 127 common frames omitted
Project class is
#Data #Entity #Table(name = "PROJECT", schema = "DCS") public class Project implements Identifiable<Integer> {
#Id
#Column(name = "PRJ_I", nullable = false)
private Integer id;
#Column(name = "PRJ_NM")
private String projectName;
#OneToOne
#JoinColumn(name="PRJ_I")
private CcpaCustomerProjectGroup ccpaCustomerProjectGroup;
}
CcpaCustomerProjectGroup is
#Data #Entity #Table(name = "CCPA_CUS_PRJ_GRP", schema = "DCS") public class CcpaCustomerProjectGroup implements Identifiable<Integer> {
#Id
#Column(name="CCPA_CUS_PRJ_GRP_I")
private Integer id;
#Column(name="CUS_PRJ_GRP_I")
private Integer customerProjectGroupId;
#Column(name="PRJ_I")
private Integer projectId;
/*#OneToOne
#PrimaryKeyJoinColumn
private Project project;*/
}
ProjectRepository is
public interface ProjectRepository extends JpaRepository<Project, Integer>,JpaSpecificationExecutor<Project>, QueryDslPredicateExecutor<Project> {
#Query(value="select p.PRJ_I,p.PRJ_NM from CCPA_CUS_PRJ_GRP c,project p where c.CUS_PRJ_GRP_I = ?1 and c.PRJ_I = p.PRJ_I and p.PRJ_NM like ?2", nativeQuery = true)
List<Project> find(#Param("clientId") Integer clientId, #Param("projectName") String projectName);
}
As already stated by JB in the comments, this is the important part of the stack trace:
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=RCON411.PROJECT, DRIVER=4.11.69
First confirm that DCS.PROJECT exists in the datasource you are working with, and that the user you are connecting with in your application has the necessary grants to view it.
Similarly, Looks like the PROJECT table might be trying to get accessed from the wrong schema. Does the user you are using to connect to DB2 in your app have access to the DCS schema? And if so, you may need to set the CURRENT_SCHEMA to be DCS.

SQL0913 Row or object table in Schema type *FILE in use

I am having a transaction using spring data , and I am trying to do an save operation (insert operation) . [SQL0913] Row or object table in Schema type *FILE in use.
Following is the entity
#Entity
#IdClass(OsytxlId.class)
#Table(name="OSYTXL")
#NamedQuery(name="Osytxl.findAll", query="SELECT o FROM Osytxl o")
public class Osytxl implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name="TLCONO")
private BigDecimal tlcono;
#Id
#Column(name="TLDIVI")
private String tldivi;
#Id
#Column(name="TLLINO")
private BigDecimal tllino;
#Column(name="TLLMTS")
private BigDecimal tllmts;
#Id
#Column(name="TLLNCD")
private String tllncd;
#Column(name="TLTX60")
private String tltx60;
#Id
#Column(name="TLTXID")
private BigDecimal tltxid;
#Id
#Column(name="TLTXVR")
private String tltxvr;
//getter and setters
}
I am using springdata-jpa
And I am calling the following code portion from the service implementation class
Before the following insertion , I need to delete the contents before insert .
Osytxl osytxl = null;
Collection<Osytxl> osytxlList = new ArrayList<Osytxl>();
for (int lineNo = 0; lineNo < lines.length; lineNo++) {
osytxl = new Osytxl();
osytxl.setTlcono(osytxh.getThcono());
osytxl.setTldivi(osytxh.getThdivi());
osytxl.setTltxid(osytxh.getThtxid());
osytxl.setTltxvr(osytxh.getThtxvr());
osytxl.setTllncd(osytxh.getThlncd());
osytxl.setTllmts(new BigDecimal("1437651510403"));
osytxl.setTllino(new BigDecimal(lineNo+1));
osytxl.setTltx60(lines[lineNo]);
osytxlList.add(osytxl);
}
if(osytxlList.size()>0)
osytxlRepository.save(osytxlList);
And I am using JPA repository But I am getting the following exception
org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.GenericJDBCException: could not execute statement; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:415)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:418)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy107.saveAndFlush(Unknown Source)
........................................................
Caused by: java.sql.SQLException: [SQL0913] Row or object OSYTXL in schema type *FILE in use.
at com.ibm.as400.access.JDError.createSQLExceptionSubClass(JDError.java:877)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:706)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:676)
at com.ibm.as400.access.AS400JDBCStatement.commonExecute(AS400JDBCStatement.java:1021)
at com.ibm.as400.access.AS400JDBCPreparedStatement.executeUpdate(AS400JDBCPreparedStatement.java:1825)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
... 127 more
I am using iseries (DB2) .Am I missing something or there anything I need to do extra in persistence.xml . Can anyone help .
I've found on Experts Exchange that this could be due to queries outside of your application, locking the required records.
Adding FOR READ ONLY to your query like this:
SELECT * FROM FILE.TABLE
FOR READ ONLY

what does the return value of #Modifying methods in Spring Data JPA mean

#Repository
public interface LoginDao extends JpaRepository<LoginEntity, Integer> { //}, LoginDaoCustom {
LoginEntity findByLogin(String login);
#Modifying
int changePassword(String password, String login);
}
If I change the return value of the changePassword to anything other than int, I get the error below.
Caused by: java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as return type!
at org.springframework.util.Assert.isTrue(Assert.java:65)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.<init>(JpaQueryExecution.java:166)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.getExecution(AbstractJpaQuery.java:106)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:86)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:337)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
... 46 more
What does this integer return value mean ? I am sure spring has it documented somewhere, but I can't find it. It is not listed in the jpa.modifying-queries
I should add that if do declare the return type as int, the update fails silently and values aren't updated.
The int/Integer return value is the number of rows that where updated in the database.

Spring Data MongoDB with Java 8 LocalDate MappingException

I try to use the LocalTime from Java 8 Date Time API with Spring Data MongoDB. Inserting the document works as expected, but when I try to read the document, I get the following error:
Exception in thread "main" java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:637)
....
Caused by: org.springframework.data.mapping.model.MappingException: No property null found on entity class java.time.LocalDate to bind constructor parameter to!
at org.springframework.data.mapping.model.PersistentEntityParameterValueProvider.getParameterValue(PersistentEntityParameterValueProvider.java:74)
at org.springframework.data.mapping.model.SpELExpressionParameterValueProvider.getParameterValue(SpELExpressionParameterValueProvider.java:63)
at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:71)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:257)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:237)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1109)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.access$100(MappingMongoConverter.java:78)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1058)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:789)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:270)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:263)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:261)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:263)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:237)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:201)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:197)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:78)
at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:2005)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1699)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1522)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1506)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:532)
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.findAll(SimpleMongoRepository.java:217)
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.findAll(SimpleMongoRepository.java:174)
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.findAll(SimpleMongoRepository.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:358)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy28.findAll(Unknown Source)
at hello.Application.run(Application.java:36)
at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:634)
... 5 more
I tried this with the example from the Spring website: http://spring.io/guides/gs/accessing-data-mongodb/
I just changed to Customer to have a birthdate:
package hello;
import org.springframework.data.annotation.Id;
import java.time.LocalDate;
public class Customer {
#Id
private String id;
private String firstName;
private String lastName;
private LocalDate birthDay;
public Customer() {}
public Customer(String firstName, String lastName, LocalDate birthDay) {
this.firstName = firstName;
this.lastName = lastName;
this.birthDay = birthDay;
}
#Override
public String toString() {
return String.format(
"Customer[id=%s, firstName='%s', lastName='%s']",
id, firstName, lastName);
}
}
I wrote this little bit of code for all 4 of these conversion options:
DateToLocalDateTimeConverter
DateToLocalDateConverter
LocalDateTimeToDateConverter
LocalDateToDateConverter
Here is an example
public class DateToLocalDateTimeConverter implements Converter<Date, LocalDateTime> {
#Override
public LocalDateTime convert(Date source) {
return source == null ? null : LocalDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());
}
}
All example here.
Then by including this in the xml configuration for the mongodb connection I was able to work in java 8 dates with mongodb (remember to add all the converters):
<mongo:mapping-converter>
<mongo:custom-converters>
<mongo:converter>
<bean class="package.DateToLocalDateTimeConverter" />
</mongo:converter>
</mongo:custom-converters>
</mongo:mapping-converter>
Now problem is resolved:
https://jira.spring.io/browse/DATAMONGO-1102
But Spring Data doesn't support ZonedDateTime now, only Local.
This is currently not supported mostly due to the fact that MongoDB doesn't support storing Java 8 date time types right now. I suggest to turn the internal property into a legacy Date one and do the conversions on the API of the domain class (as you would do with Hibernate and JodaTime e.g.).

Resources