API method OClass.setCustom fails in distributed environment when trying to write text containing spaces - orientdb

I've implemented an OrientDB client using the Java-API (Version 3.0.30). My code makes heavy usage of custom fields in order to store meta data to schema classes.
In the development and integration test environment everything works fine. In the production environment my initialization method fails at the first setCustom command that writes a text containing spaces to a cutom field. The a OCommandSQLParsingException is thrown (see below).
In the dev/test environment I'm using all sorts of databases (embedded, plocal and remote access to a standalone OrientDB instance - running on docker).
In the production environment the application connects to a distributed cluster of several OrientDB instances (all docker containers). That's the only difference I can spot.
The initialization code looks like this:
try(ODatabaseSession session = orientDbService.getSession()) {
final String className = "mySuperClass";
OClass oClass = session.getMetadata().getSchema().getClass(className);
if(oClass == null) {
oClass = session.createVertexClass(className);
oClass.setAbstract(true);
oClass.setCustom("myDescription", "my superclass"); // <- fails here in production
oClass.setCustom("myCreationDate", ...
The error occors when the text to be written to the custom field contains spaces. Text without spaces is processed without problems.
This exception is thrown:
OCommandSQLParsingException: Error parsing query:
alter class `mySuperClass` custom `myDescription`=my superclass
^
Encountered " <IDENTIFIER> "superclass "" at line 1, column 53.
Was expecting one of:
<EOF>
<UNSAFE> ...
";" ...
<UNSAFE> ...
<UNSAFE> ...
DB name="myDb"
Error Code="1"
at com.orientechnologies.orient.core.sql.parser.OStatementCache.throwParsingException(OStatementCache.java:149)
at com.orientechnologies.orient.core.sql.parser.OStatementCache.parse(OStatementCache.java:141)
at com.orientechnologies.orient.core.sql.parser.OStatementCache.get(OStatementCache.java:90)
at com.orientechnologies.orient.core.sql.parser.OStatementCache.get(OStatementCache.java:68)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLAbstract.preParse(OCommandExecutorSQLAbstract.java:228)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLAlterClass.parse(OCommandExecutorSQLAlterClass.java:60)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLAlterClass.parse(OCommandExecutorSQLAlterClass.java:44)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:58)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:39)
at com.orientechnologies.orient.server.distributed.impl.ODistributedStorage.command(ODistributedStorage.java:240)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:68)
at com.orientechnologies.orient.core.metadata.schema.OClassEmbedded.setCustom(OClassEmbedded.java:198)
at com.orientechnologies.orient.core.metadata.schema.OClassEmbedded.setCustom(OClassEmbedded.java:24)
at com.orientechnologies.orient.core.sql.parser.OAlterClassStatement.executeDDL(OAlterClassStatement.java:318)
at com.orientechnologies.orient.core.sql.executor.ODDLExecutionPlan.executeInternal(ODDLExecutionPlan.java:55)
at com.orientechnologies.orient.core.sql.parser.ODDLStatement.execute(ODDLStatement.java:42)
at com.orientechnologies.orient.core.sql.parser.OStatement.execute(OStatement.java:79)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded.command(ODatabaseDocumentEmbedded.java:567)
at com.orientechnologies.orient.server.OConnectionBinaryExecutor.executeQuery(OConnectionBinaryExecutor.java:1188)
at com.orientechnologies.orient.client.remote.message.OQueryRequest.execute(OQueryRequest.java:136)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.sessionRequest(ONetworkProtocolBinary.java:310)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.execute(ONetworkProtocolBinary.java:212)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:69)
The following parameters are identical in develop, test and prod environment:
Version: OrientDB 3.0.30 (Java API, servers)
Java Runtime: OpenJDK 11
OS: Linux

Related

Programmatically load openjpa javaagent - runtime optimization

I am writing unit test for testing JPA DAO and I would like to automatically load the javaagant (JPA class enhancer) without having to specify the -javaagent vm parameter.
To achieve this I implemented a #BeforeClass annotated method like this:
String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
String pid = nameOfRunningVM.substring(0, nameOfRunningVM.indexOf('#'));
VirtualMachine vm = VirtualMachine.attach(pid);
vm.loadAgent("openjpa-all-2.4.2.jar");
vm.detach();
emf = Persistence.createEntityManagerFactory("TEST_DB");
But I still get the error telling entity classes were not enhanced when creating the entity manager factory.
org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: ")
I can live with the -javaagent parameter but I am curious and would be pleased if anybody could share a solution or idea with us.
I am running my test with JUnit and Java 8

Grails afterInsert hook issue with Hibernate 5.1 and PostgreSQL

In an existing Grails 3.1.15 application, recently upgraded to Hibernate 5.1, an odd issue with afterInsert (or other) hooks started to appear. After some hours of testing, I could track this down to Hibernate 5.1 + PostgreSQL combination - issue is not reproducible with H2. To reproduce, create a simple application consisting of 2 domain objects - an Audit trail and a User, as shown here:
class Audit {
Date dateCreated
String auditData
}
class User {
String name
String email
def afterInsert() {
new Audit(auditData: "User created: $this").save()
}
}
The code above works OK with Hibernate 4, however, if the application is upgraded to Hibernate5 plugin + Hibernate 5.1.x (tested with 5.1.0.Final and 5.1.5.Final) the above scenario will always lead to a ConcurrentModificationException when you attempt to save a new User instance. You can just use a scaffold controller to reproduce. Note this only happens with PostgreSQL as the data source - with H2 it would still work OK.
Now, according to GORM Docs (see chapter 8.1.3) one should use a new session when attempting to save other objects in beforeUpdate or afterInsert hooks anyway:
def afterInsert() {
Audit.withNewSession() {
new Audit(auditData: "User created: $this").save()
/* no exception logged, but Audit instance not preserved */
}
}
But this wouldn't really resolve the issue with PSQL. The exception is gone, the User instance is persisted, but the Audit instance is not saved. Again, this code would work OK with H2. To really avoid the issue with PSQL, you would have to manually flush the session in afterInsert:
def afterInsert() {
Audit.withNewSession() { session ->
new Audit(auditData: "User created: $this").save()
session.flush()
/* finally no exceptions, both User and Audit saved */
}
}
Question: is this a bug, or is this expected? I find it a bit suspicious that the manual flush is required in order for the Audit instance to be persisted - and even more so when I see it works without a flush with H2 and only seems to affect PostgreSQL. But I couldn't really find any reports - any pointers are appreciated!
For the sake of completeness, I tested with the following JDBC driver versions for PostgreSQL:
runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
runtime 'org.postgresql:postgresql:9.4.1208.jre7'
runtime 'org.postgresql:postgresql:42.0.0'
And for the upgrade to Hibernate 5.1, the following dependencies were used:
classpath "org.grails.plugins:hibernate5:5.0.13"
...
compile "org.grails.plugins:hibernate5:5.0.13"
compile "org.hibernate:hibernate-core:5.1.5.Final"
compile "org.hibernate:hibernate-ehcache:5.1.5.Final"

org.activiti.rest.editor.model.ModelEditorJsonRestResource - Error creating model JSON

I work with activiti-5.15.1
I deploy activiti-explorer and activiti-rest under my server tomcat-6.0.18\webapps
I related this war with postgres as a database
I change in db.properties in activiti-explorer and activiti-rest
db=postgres
jdbc.driver=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/activiti
jdbc.username=postgres
jdbc.password=postgres
and I put postgresql-jdbc3-8.1-405.jar under lib folder
when I start the server 23 table are created,
but using http://com.supcom:8080/activiti-explorer/
when I try to create a new model I have this error :
ERROR org.activiti.rest.editor.model.ModelEditorJsonRestResource - Error creating model JSON
org.codehaus.jackson.JsonParseException: Unexpected character ('j' (code 106)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: java.io.StringReader#390afb; line: 1, column: 2]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442)
at org.codehaus.jackson.impl.ReaderBasedParser._handleUnexpectedValue(ReaderBasedParser.java:1198)
at org.codehaus.jackson.impl.ReaderBasedParser.nextToken(ReaderBasedParser.java:485)
at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2770)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2718)
at org.codehaus.jackson.map.ObjectMapper.readTree(ObjectMapper.java:1542)
at org.activiti.rest.editor.model.ModelEditorJsonRestResource.getEditorJson(ModelEditorJsonRestResource.java:53)
the same error is displayed when I try to import other model which is created under eclipse using activiti plugin
This error is due to the multiple versions of PostgreSQL jar.
According to postgresql website https://jdbc.postgresql.org/download.html
If you are using JDK 1.6 then the JDBC4 is suitable.(JDBC4 Postgresql Driver, Version 9.4-1208).
The jar must be used in activiti-explorer lib folder , your application and tomcat lib folder.

Spring Data Cassandra - Environment must not be null Error

I am following basic tutorial at Spring Data Cassandra reference http://docs.spring.io/spring-data/cassandra/docs/1.1.0.RC1/reference/html/ and I am running into following exception
java.lang.IllegalArgumentException: Environment must not be null!
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.data.repository.config.RepositoryConfigurationSourceSupport.<init>(RepositoryConfigurationSourceSupport.java:50)
at org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(AnnotationRepositoryConfigurationSource.java:74)
at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:74)
at org.springframework.context.annotation.ConfigurationClassParser.processImport(ConfigurationClassParser.java:394)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:204)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:163)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:138)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:284)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:225)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:73)
at com.strides.platform.domain.UserRepositoryDaoTest.<init>(UserRepositoryDaoTest.java:28)
I have completed steps mentioned in document,
1) Use Cassandra Properties
2) Create Java configuration
3) Create domain and repository classes
I have autowired Environment variable in Test classes. I checked couple of sample projects and not sure what needs to be done more.
I've encountered this error message and found the problem only occuring when I used Spring Framework version 3.2.8.RELEASE.
My solution was to upgrade to version 3.2.9.RELEASE.
See also java.lang.IllegalArgumentException: Environment must not be null

Undefined method `FactoryGirl' -- upgrading from 2.0.2 to 3.4.2

I'm in the process of upgrading from factory_girl (2.0.2 to 3.4.2) and factory_girl_rails (1.1.0 -> 3.4.0)
and I'm having issues with my rspec tests seeing factory girl.
I think I've successfully altered my factories to deal with the new syntax, and have removed the extra require statements that were bringing in multiple copies of the same files. My server now starts up, so I know that the factories.rb file is correctly getting parsed.
Now when I run my rspec tests, I'm getting this error:
NoMethodError: undefined method `FactoryGirl' for #
it 'can be created' do
course = FactoryGirl(:course)
….
end
With Factory Girl 3.4.2, you will need to explicitly use the create method.
course = FactoryGirl.create(:course)