Additional Feature Release V2.2.10 morphium

veröffentlicht am : Mo, 29. 09. 2014 geändert am: Mo, 29. 09. 2014

Schlagworte:


New Release of Morphium V2.2.10

available at github

background

The last release was reported not to work properly in Tomcat or J2EE-Environments. The reason is the classpath scanning feature added with the last release. For type ids to work properly, morphium needs to scan the whole classpath for entities, in order to be able to determine the type of a db-object upon de-serialization.

This works fine, for applications and a like, but does have it's drawbacks in J2ee-Environments like a servlet engine (e.g. Tomcat, Jetty, Jboss).

In that environment you need to define a filter or some kind of startup hook, so that the additional classpath entries might be added to morphium.

If this does not happen, morphium tries to figure out the type by itself - but might fail, depending on your setup.

howto

It is recommended to make classpath elements known to morphium, using this call:

morphium.getMapper().getEntityCache().addClassPathElement("/opt/tomcat/webapps/myapp/WEB-INF/classes");

you need to add all pathes which might contain entities, pathes might be directories, .class files or jars.

In a webapp / servlet based application, you could easily do that to one of your filters, or other initialization code. Please keep in mind, that this will only work, if classpath is already set correctly.

Morphium already scans the "default" classpath upon startup, but in Webapps, this is changed. You could do something like this in order to get everything to work. In tomcat this might work:

for (Url u:((WebappClassLoader)getClass().getClassLoader()).getUrls()) {
   morphium.getMapper().getEntityCache().addClassPathElement(u.getFile());
}

Attention: This code might load classes, you don't want to be loaded. ;-)

erstellt Stephan Bösebeck (stephan)