I have the following class which is persisted into a mongodb using morphia in a play! application. The class resides in a module which is a dependency of another play! application.
Its configuration is read from a file and persisted into the db on initial load (if its not already in the db) and then subsequent requests use the db version.
#Entity
public class Page extends Model {
#Id
public Long navigationId;
// etc ...
}
The initial load and subsequent query access works ok and i can see the page in mongo:
> db.Page.find({_id:20000})
{ "_id" : NumberLong(20000), "className" : "models.Page" etc }
However if i restart play! or make a code change that results in Morphia being reinitialised
(MorphiaPlugin-1.2.4> initialized appears in the logs) i get the following stack trace:
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:487)
at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:267)
at com.google.code.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:66)
at com.google.code.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:53)
at com.google.code.morphia.query.MorphiaIterator.next(MorphiaIterator.java:48)
at com.google.code.morphia.query.QueryImpl.asList(QueryImpl.java:255)
at play.modules.morphia.Model$MorphiaQuery.asList(Model.java:1067)
at models.Page.findAll(Page.java)
at plugins.PageConfigLoadPlugin.loadPersistedPages(PageConfigLoadPlugin.java:62)
at plugins.PageConfigLoadPlugin.onApplicationStart(PageConfigLoadPlugin.java:51)
at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:425)
at play.Play.start(Play.java:495)
... 3 more
Caused by: java.lang.RuntimeException: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
at com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:27)
at com.google.code.morphia.mapping.Mapper.readMappedField(Mapper.java:501)
at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:484)
... 14 more
Caused by: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
at com.google.code.morphia.converters.DefaultConverters.fromDBObject(DefaultConverters.java:133)
at com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:25)
... 16 more
If i drop the Collection from mongodb using the command line i can again load and query the Page obejct successfully from my play! web application
> db.Page.drop()
true
As I mentioned, this class is in a module. This problem only happens in one application that the module is a dependency of. The other demo application works fine.
any suggestions?
Does the dependent module have another alternate declaration of the Page or
Model classes?
From the top of the stack trace, ("com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000"), it looks like there's a type mismatch between
the way a numeric value is being stored and retrieved. For example, in Java,
it is not uncommon to store something as a Double and then mistakenly try
to retrieve it as an Integer or a Long. So, can you verify that the
declaration of navigationId in the dependent module is the same as the one
you've shown here? They should share the definition, but its possible there's
an alternate.
Another thing to check is that your code is putting a Long into your
DBObject and not a float. For example, if you're inserting it via the shell,
you'll need to use one of the wrappers, e.g.
db.Page.save({_id:NumberLong(20000)});
Otherwise, this will also cause a mismatch when you retrieve it; by default
numbers in JavaScript are doubles.
Related
I have a quite big (>2.5 GB) h2 database file. Driver version is 1.4.182. Everything worked fine but recently the DB stop to work with exception:
Błąd ogólny: "java.lang.NullPointerException"
General error: "java.lang.NullPointerException" [50000-182] HY000/50000 (Help)
org.h2.jdbc.JdbcSQLException: Błąd ogólny: "java.lang.NullPointerException"
General error: "java.lang.NullPointerException" [50000-182]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.message.DbException.convert(DbException.java:295)
at org.h2.engine.Database.openDatabase(Database.java:297)
at org.h2.engine.Database.<init>(Database.java:260)
at org.h2.engine.Engine.openSession(Engine.java:60)
at org.h2.engine.Engine.openSession(Engine.java:167)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:145)
at org.h2.engine.Engine.createSession(Engine.java:128)
at org.h2.engine.Engine.createSession(Engine.java:26)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:347)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:108)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:92)
at org.h2.Driver.connect(Driver.java:72)
at org.h2.server.web.WebServer.getConnection(WebServer.java:750)
at org.h2.server.web.WebApp.test(WebApp.java:895)
at org.h2.server.web.WebApp.process(WebApp.java:221)
at org.h2.server.web.WebApp.processRequest(WebApp.java:170)
at org.h2.server.web.WebThread.process(WebThread.java:137)
at org.h2.server.web.WebThread.run(WebThread.java:93)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at org.h2.mvstore.db.ValueDataType.compare(ValueDataType.java:102)
at org.h2.mvstore.MVMap.compare(MVMap.java:741)
at org.h2.mvstore.Page.binarySearch(Page.java:388)
at org.h2.mvstore.MVMap.put(MVMap.java:179)
at org.h2.mvstore.MVMap.put(MVMap.java:133)
at org.h2.mvstore.db.TransactionStore.rollbackTo(TransactionStore.java:491)
at org.h2.mvstore.db.TransactionStore$Transaction.rollback(TransactionStore.java:785)
at org.h2.mvstore.db.MVTableEngine$Store.initTransactions(MVTableEngine.java:223)
at org.h2.engine.Database.open(Database.java:736)
at org.h2.engine.Database.openDatabase(Database.java:266)
... 17 more
The problem occurs in my application and using H2 web frontend.
I have tried solution from similar question but I cannot downgrade H2 to 1.3.x as it cannot read 1.4.x DB files.
My questions are:
How to handle it? Is it to possible to make it work again? I have tried downgrade H2 to 1.4.177 but it didn't help.
Is there any way to at least recover data to other format? I could use other DB (Sqlite, etc.) however I would need a way to get to these data.
EDIT: updated stacktrace
EDIT 2: Result of using Recovery tool:
$ java -cp h2-1.4.182.jar org.h2.tools.Recover
Exception in thread "main" java.lang.IllegalStateException: Unknown tag 50 [1.4.182/6]
at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:762)
at org.h2.mvstore.type.ObjectDataType.read(ObjectDataType.java:222)
at org.h2.mvstore.db.TransactionStore$ArrayType.read(TransactionStore.java:1792)
at org.h2.mvstore.db.TransactionStore$ArrayType.read(TransactionStore.java:1759)
at org.h2.mvstore.Page.read(Page.java:843)
at org.h2.mvstore.Page.read(Page.java:230)
at org.h2.mvstore.MVStore.readPage(MVStore.java:1813)
at org.h2.mvstore.MVMap.readPage(MVMap.java:769)
at org.h2.mvstore.Page.getChildPage(Page.java:252)
at org.h2.mvstore.MVMap.getFirstLast(MVMap.java:351)
at org.h2.mvstore.MVMap.firstKey(MVMap.java:218)
at org.h2.mvstore.db.TransactionStore.init(TransactionStore.java:169)
at org.h2.mvstore.db.TransactionStore.<init>(TransactionStore.java:117)
at org.h2.mvstore.db.TransactionStore.<init>(TransactionStore.java:81)
at org.h2.tools.Recover.dumpMVStoreFile(Recover.java:593)
at org.h2.tools.Recover.process(Recover.java:331)
at org.h2.tools.Recover.runTool(Recover.java:192)
at org.h2.tools.Recover.main(Recover.java:155)
I also noticed that two another files (.txt and .sql) has been created but they don't seem to contain a data.
I got the same situation last week with JIRA database, it took me few hours to do google regarding to this problem however, there are no answers which can resolve the situation.
I decided to take a look at H2 source code and I can recover the whole database with very simple code. I may not understand whole picture about the situation e.g. root cause, in which condition it happened, etc.
However, the cause is: when you connect to h2 file then H2 engine will look into auditLog and rollback the in-progress transactions, there are some data which have unknown type (id is 17) and H2 fails to rollback due to exception during recognize the type (id 17).
My code is simple, add h2 lib into your build path then just manual connect to file and clear auditLog because I think it is just the log and will not have big impact (someone may correct me).
Hopefully, you can resolve your problem as well.
public static void main(final String[] args) {
// open the store (in-memory if fileName is null)
final MVStore store = MVStore.open("C:\\temp\\h2db.mv.db");
final MVMap<Object, Object> openMap = store.openMap("undoLog");
openMap.clear();
// close the store (this will persist changes)
store.close();
}
Another solution for this problem:
Go to your home folder (~ in linux).
Move all files named [*.mv.db] to a backup with a different name. For example: mv xyz.mv.db xyz.mv.db.backup
Restart your database.
This seems to clear out MVStore meta-data used for H2 undo features, and resolves the NPE from the MV Store compare.
I had a similar problem:
[HY000][50000] Allgemeiner Fehler: "java.lang.NullPointerException"
General error: "java.lang.NullPointerException" [50000-176]
java.lang.NullPointerException
I tried to connect with IntelliJ to H2 file DB. H2 driver version was 1.3.176 but the DB file version had 1.3.161. So downgraded the driver to 1.3.161 in IntelliJ solved the problem completely.
I tried to make the zenTasks tutorial for the play-java framework (I use the current playframework, which is 2.3.2). As it comes to testing and adding fixtures I'm kind of lost!
The docu states that
Edit the conf/test-data.yml file and start to describe a User:
- !!models.User
email: bob#gmail.com
name: Bob
password: secret
...
And I should download a sample (which is in fact a dead link!)
So I tried myself adding more Users like this:
- !!models.User
email: somemail1#example.com
loginName: test1
- !!models.User
email: somemail2#example.com
loginName: test2
If I then try to load it via
Object load = Yaml.load("test-data.yml");
if (load instanceof List){
List list = (List)load;
Ebean.save(list);
} else {
Ebean.save(load);
}
I get the following Exception:
[error] Test ModelsTest.createAndRetrieveUser failed:
java.lang.IllegalArgumentException: This bean is of type [class
java.util.ArrayList] is not enhanced?, took 6.505 sec [error] at
com.avaje.ebeaninternal.server.persist.DefaultPersister.saveRecurse(DefaultPersister.java:270)
[error] at
com.avaje.ebeaninternal.server.persist.DefaultPersister.save(DefaultPersister.java:244)
[error] at
com.avaje.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1610)
[error] at
com.avaje.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1600)
[error] at com.avaje.ebean.Ebean.save(Ebean.java:453) [error]
at ModelsTest.createAndRetrieveUser(ModelsTest.java:18) [error]
...
How Am I supposed to load more than one User (or whatever object I wish) and parse them without exception?
In Ebean class save method is overloaded.
save(Object) - expects parameter which is entity (extends Model, has #Entity annotation)
save(Collection) - expects collection of entities.
Yaml.load function returns objecs which can be:
Entity
List of entities
But if we simply do:
Object load = Yaml.load("test-data.yml");
Ebean.save(load);
then save(Object) method will be called. This is because at compile time compiler doesn't know what exactly will Yaml.load return. So above code will throw exception posted is question when there is more then one user in "test-data.yml" file.
But when we cast the result to List as in code provided by OP then everything works good. save(Collection) method is called and all entities are saved correctly. So the code from question is correct.
I have same problem with loading data from "test-data.yml". But I have found solution for this problem. Here is http://kewool.com/2013/07/bugs-in-play-framework-version-2-1-1-tutorial-fixtures/ solution code. But all Ebean.save methods must be replaced with Ebean.saveAll methods.
I want to use Uniqueness for my Traversal.
Based on this tutorial, I'm using the following code :
GraphDatabaseService database = new RestGraphDatabase("http://localhost:7474/db/data");
TraversalDescription td = database.traversalDescription().uniqueness(Uniqueness.RELATIONSHIP_GLOBAL);
This code gave me the following error :
Exception in thread "main" java.lang.UnsupportedOperationException: Only values of class org.neo4j.kernel.Uniqueness are supported
at org.neo4j.rest.graphdb.traversal.RestTraversal.restify(RestTraversal.java:63)
at org.neo4j.rest.graphdb.traversal.RestTraversal.uniqueness(RestTraversal.java:54)
at org.neo4j.rest.graphdb.traversal.RestTraversal.uniqueness(RestTraversal.java:50)
at org.neo4j.rest.graphdb.traversal.RestTraversal.uniqueness(RestTraversal.java:37)
I already had to change the Traversal.description() to database.traversalDescription() because of deprecated but now I face the same problem for Uniqueness. In my example I used org.neo4j.graphdb.traversal.Uniquess because org.neo4j.kernel.Uniqueness is deprecated...
When using the package mentionned by the error I have a NullPointerException during the traverse() method, with no stack trace.
I'm using :
REST API : neo4j-rest-graphdb-2.0.0-M06.jar
Neo4j : neo4j-desktop-2.0.0.jar
Best regards.
There have been API changes in Neo4j 2.0 which are not in neo4j-rest-graphdb-2.0.0-M06
If you pull the latest neo4j-rest-graphdb github repo and build it locally it should work against: neo4j-rest-graphdb-2.0.0-SNAPSHOT
I'm trying to add new keys in application.conf file in play framework 2.1. I have added the following keys:
gen.db.host=localhost
gen.db.port=27017
gen.db.name=test
When i start my application, it is throwing the following error:
Configuration error: Configuration error[application.conf: 46: port has type NUMBER rather than OBJECT]
......
......
......
Caused by: com.typesafe.config.ConfigException$WrongType: application.conf: 46: port has type NUMBER rather than OBJECT
I don't understand this issue. How can i resolve it? Also, is it a good practice to define new keys in application.conf file?
Thanks.
Put the port between double quotes:
gen.db.port="27017"
You have to use a colon
gen.dn.port:"26017"
Here's a link to the current documentation
http://www.playframework.com/documentation/2.0.x/Configuration
You are propably using wrong method to extract the data from config. I assume you use it like:
current.configuration.getConfig("gen.db.port")
But this method returns play.api.Configuration and expects an object to be under the path "gen.db.port" (as it is mentioned in the error). Since under the "gen.db.port" path you have a number, you should change the method to:
current.configuration.getNumber("gen.db.port")
Code is in Scala. It is extremely similar to Java code.
Code that our map indexer uses to create index: https://gist.github.com/a16e5946b67c6d12b2b8
Utilities that the above code uses to create index and mapping: https://gist.github.com/4f88033204cd761abec0
Errors that java gives: https://gist.github.com/d6c835233e2b606a7074
Response of http://elasticsearch.domain/maps/_settings after running code and getting errors: https://gist.github.com/06ca7112ce1b01de3944
JSON FILES:
https://gist.github.com/bbab15d699137f04ad87
https://gist.github.com/73222e300be9fffd6380
Attached are the json files i'm loading in. I have confirmed that it is loading the right json files and properly outputting it as a string into .loadFromSource and .setSource.
Any ideas why it can't find the analyzers even though they are in _settings? If I run these json files via curl they work fine and properly setup the mapping.
The code I was using to create the index (found here: Define custom ElasticSearch Analyzer using Java API) was creating settings in the index like:
"index.settings.analysis.filter.my_snow.type: "stemmer","
It had settings in the setting path.
I changed my indexing code to the following to fix this:
def createIndex(client: Client, indexName: String, indexFile: String) {
//Create index
client.admin().indices().prepareCreate(indexName)
.setSource(Utils.loadFileAsString(indexFile))
.execute()
.actionGet()
}