7 Replies Latest reply on Feb 1, 2011 2:46 PM by Michal Frackowiak

    Extending EntityHome

    Oguzhan YALCIN Newbie

      Hi ,


      I'm trying to extend the xxxHome (where xxx isteh entity name), but when I extend the xxxHome and try to access it, an error occurs like below:



      Caused by: java.lang.IllegalArgumentException: Could not guess entity class by reflection
           at org.jboss.seam.framework.Home.getEntityClass(Home.java:267)
           at org.jboss.seam.framework.Home.create(Home.java:103)
           at org.jboss.seam.framework.EntityHome.create(EntityHome.java:30)
           at sun.reflect.GeneratedMethodAccessor392.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:95)
           at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
           at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at com.taykos.extension.home.SocialSecurityInformationHome_$$_javassist_30.create(SocialSecurityInformationHome_$$_javassist_30.java)
           at sun.reflect.GeneratedMethodAccessor697.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
           at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
           at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
           at org.jboss.seam.Component.newInstance(Component.java:2094)
           ... 179 more



      How can I solve the problem? Thx

        • 1. Re: Extending EntityHome
          Michael Wohlfart Expert

          looks like you didn't set the generic type parameter in your subclass of EntityHome?


          public class PersonHome extends EntityHome<Person> {
             ....
          }






          • 2. Re: Extending EntityHome
            Oguzhan YALCIN Newbie

            Hi,
            I'll put the whole story on the board. I use seam generate entities from seam development tools. It generates the whole site according to the db. The files generated are:




            -- xxx.java (Entity)
            -- xxxHome.java (Home class extending entityHome <xxx>. like you described above)
            -- xxxList.java (One for listing entities)




            ...


            when I make a  change on db I re-use the same tool and it overwrites all these files. So the changes I've made before are all gone. To prevent this I extend the classes (xxxList & xxxHome) and add my custom functions to the classes I've written. BTW the changes I've made always stays there.


            So now :




            //This is the class generated by Seam development Tools
            public class PersonHome extends EntityHome<Person> {
               ....
            }



            //This is the class I've generated
            public class MyPersonHome extends PersonHome {
               ....
            }



            the error occurs when I try  to create an instance of MyPersonHome.
            Any sugestions?



            • 3. Re: Extending EntityHome
              Michael Wohlfart Expert

              as far as I understand the call to Home.getEntityClass() fails because because the class MyPersonHome is not a ParameterizedType, what you can try to do is implement your own getEntityClass() method in MyPersonHome:




                  @Override
                  public Class<Person> getEntityClass() {
                       return Person.class;
                  }


              • 4. Re: Extending EntityHome
                Oguzhan YALCIN Newbie

                That solved the problem.Thx Michael

                • 5. Re: Extending EntityHome
                  first last Newbie

                  In my case I simply needed a common base class for all my xxxHome classes to extend.
                  This was done by:


                  public class MyHome<E> extends EntityHome<E> {
                       ... my common Home operations ...
                  }




                  And then each specific xxxHome extended MyHome,
                  and only that final level of extension supplied the E type argument, e.g.




                  @Name("productHome")
                  public class ProductHome extends MyHome<Product> {
                       ... my ProductHome specific operations ...
                  }

                  • 6. Re: Extending EntityHome
                    boris Simo Newbie

                    Hi,


                    I extends the XXXHome so:



                    @Name("extClientHome")
                    public class ExtClientHome extends ClientHome{
                      ...         ....
                    }



                    The thing is, my view don't recognize the class, when I do:



                    <h:inputtext ... action=#{extClientHome.instance.name}



                    I don't know, where is the problem?




                    • 7. Re: Extending EntityHome
                      Michal Frackowiak Newbie

                      Don't you think it's a bug in JBoss Seam? If course you can always override getEntityClass method, but still the implementation should look for ancestor of the class that is EntityHome and then get the parametrized type.