Announcement Announcement Module
Collapse
No announcement yet.
Subclassed entities: java.lang.IllegalArgumentException: Unknown entity Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Subclassed entities: java.lang.IllegalArgumentException: Unknown entity

    I have a 3 level inheritance hierarchy where writing out the subclassed entity throws: java.lang.IllegalArgumentException: Unknown entity

    My classes are defined as:

    Top level :

    Code:
    @MappedSuperclass
    public abstract class AbstractContentRecord {
    2nd level, used by another app, works fine:
    Code:
    @RooJavaBean
    @RooToString 
    @RooEntity
    public class Widget extends AbstractContentRecord implements WidgetInterface {
    3rd level, used as CmWidget, fails on merge() with stack trace below:
    Code:
    @RooJavaBean
    @RooToString
    public class CmWidget extends com.foo.content.common.domain.catalog.Widget {
    The Widget I'm extending resides in a dependent maven project.
    I do have this project defined as a weave dep:
    Code:
              <weaveDependency>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>content-common</artifactId>
                </weaveDependency>
    In my controller I call a factory method to instantiate the right type of widget so I can use the same controller for both the parent and child class entities:
    Code:
        @RequestMapping(value = "/", method = RequestMethod.POST)
        @ResponseBody
        @ResponseStatus(HttpStatus.CREATED)
        public WidgetDTO createWidget(
                HttpServletRequest request,
                @Valid @RequestBody WidgetDTO transferObject) throws DuplicateEntityException {
            Widget widget = entityFactory.makeWidget();  // <<- factory method does return a CmWidget.
            widget.toEntity(transferObject);                      // pull fields from DTO into entity, verified all fields OK.
            widget = widget.merge();                              // <<- FAILS HERE
    At runtime when calling entity.merge() to save a new subclassed entity I get:

    Code:
    org.springframework.dao.InvalidDataAccessApiUsageException: Unknown entity: com.foo.content.manager.domain.catalog.CmWidget; nested exception is java.lang.IllegalArgumentException: Unknown entity: com.foo.content.manager.domain.catalog.CmWidget
            at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:286)
            at org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$18a1ac9(JpaExceptionTranslatorAspect.aj:15)
            at com.foo.content.common.domain.catalog.Widget_Roo_Entity.ajc$interMethod$com_foo_content_common_domain_catalog_Widget_Roo_Entity$com_foo_content_common_domain_catalog_Widget$merge(Widget_Roo_Entity.aj:84)
            at com.foo.content.common.domain.catalog.Widget.merge(Widget.java:1)
            at com.foo.content.common.domain.catalog.Widget_Roo_Entity.ajc$interMethodDispatch1$com_foo_content_common_domain_catalog_Widget_Roo_Entity$com_foo_content_common_domain_catalog_Widget$merge(Widget_Roo_Entity.aj)
            at com.foo.content.common.api.controller.WidgetController.createWidget(WidgetController.java:86)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
            at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
            at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
            at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
            at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
            at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
            at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
            at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:527)
            at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1216)
            at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
            at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
            at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1187)
            at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
            at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
            at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1187)
            at org.eclipse.jetty.servlets.CrossOriginFilter.handle(CrossOriginFilter.java:186)
            at org.eclipse.jetty.servlets.CrossOriginFilter.doFilter(CrossOriginFilter.java:158)
            at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1187)
            at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:421)
            at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
            at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:493)
            at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
            at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:924)
            at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:358)
            at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
            at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:860)
            at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
            at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:245)
            at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
            at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
            at org.eclipse.jetty.server.Server.handle(Server.java:335)
            at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:588)
            at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1046)
            at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:764)
            at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:217)
            at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:418)
            at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:489)
            at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436)
            at java.lang.Thread.run(Thread.java:680)
    I'm completely stuck on this. Any pointers would be greatly appreciated.

  • #2
    Didn't mention, the fact that base & subclass are in different projects, which means this is yet another case of roo's lack of multi-module support.

    https://jira.springsource.org/browse/ROO-120

    Comment


    • #3
      Just for completeness here's the problem:

      Both base & subclass, each in different maven projects, ( Widget_Roo_Entity.aj & WidgetSub_Roo_Entity.aj ) both contain this declaration and final method:

      @PersistenceContext
      transient EntityManager <class name>.entityManager;
      ...
      public static final EntityManager <class name>entityManager() {

      So subclassing a base class from another maven project cannot work because of the attempt at overriding the final method in the subclass.
      Roo does not currently look in dependent projects for base classes and will apparently assume that the absence of the base class in the current project implies that thisEntityManager element must be added to the subclass.

      it would be preferable to NOT add it as one could always manually add it if needed, but there's no mechanism for removing it other than scrapping the roo code generation for this entity hierarchy or putting them in the same project.

      Comment

      Working...
      X