0

I have inherited model classes:

public class AbstractUser extends Model

and

public class User extends AbstractUser

I'm attempting to extend from a base project into several children project. The Users in each project will have many similar base attributes, but only one or two custom attributes. I'm hoping I can extend in such a way, so when bugs/updates come in regarding base classes, I only have to make updates to the base class. Alternatively, I'll have to have duplicated code across several projects. I'm planning on extending this to other classes as well. No prob doing this with the app.controllers.

My base class of course fires up just fine. In my extended classes, I'm executing:

mvn org.javalite:activejdbc-instrumentation:1.4.12:instrument

... then moving the exploded WAR into my Jetty webapp. Whenever I hit the extended model, I get the following stack trace:

org.javalite.activejdbc.InitException: failed to determine Model class name, are you sure models have been instrumented?
at org.javalite.activejdbc.Model.modelClass(Model.java:2726)
at org.javalite.activejdbc.Model.findAll(Model.java:2349)
at com.nearstar.model.ApplicationProperties.getInstance(ApplicationProperties.java:41)
at app.controllers.LoginController.login(LoginController.java:56)
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:498)
at org.javalite.activeweb.ControllerRunner.executeAction(ControllerRunner.java:289)
at org.javalite.activeweb.ControllerRunner.run(ControllerRunner.java:65)
at org.javalite.activeweb.RequestDispatcher.doFilter(RequestDispatcher.java:202)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1676)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle(Server.java:524)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:319)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:253)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
at java.lang.Thread.run(Thread.java:745)

Is it possible to extend instrumented models in this manner?

javastunt
  • 20
  • 6

1 Answers1

1

First of all, if you get a message are you sure models have been instrumented?, it means that your models have not been instrumented. Maybe your IDE overwritten class files or script is not working, but this condition will cause this message.

Second, inheritance in ActiveJDBC does have some limitations. Please, take a look at this doc: http://javalite.io/inheritance.

What you want to do seems possible. I do not see much issue with that. However, in my projects I usually have a single common Maven module that contains all models, utility classes and services. I then use Maven dependency mechanism to pull common into other projects. This approach worked exceptionally well for many commercial projects for years.

Third, the package app.controllers is only necessary for ... controllers:) Your models can be placed into any package and module. As long as models are instrumented, and can be located on classspath, they will work as expected.

ipolevoy
  • 5,432
  • 2
  • 31
  • 46