1 2 Previous Next 15 Replies Latest reply on Jan 17, 2008 1:34 PM by itsme
      • 1. Re: Anyone have SINGLE_TABLE Entity inheritance working?
        wolfgangknauf

        Did you follow the suggestion of Felix ?

        • 2. Re: Anyone have SINGLE_TABLE Entity inheritance working?
          lpmon

          I have not gotten back to this since another project has taken priority. I will try it in the next day or so.

          Does he mean don't use the discriminator column on the subclasses? Surely you have to have it on the base class to tell the container how to detect the proper class to return.

          Thanks for the input.

          • 3. Re: Anyone have SINGLE_TABLE Entity inheritance working?
            itsme

            we got it working pretty well.

            • 4. Re: Anyone have SINGLE_TABLE Entity inheritance working?
              lpmon

              Thanks itsme

              I am using 4.0.5.GA, Hibernate 3.2.5 (per manifest file).

              Can you elaborate on your configuration? Look at my post: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=127223

              I cannot get past those problems.

              If I use insertable=false and updatable=false as the error message says I should do then I can read rows and the proper classes are returned but I cannot insert.



              • 5. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                lpmon

                Correction: Hibernate 3.2.3.GA. I looked at wrong JBoss instance

                • 6. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                  itsme

                  Can you give me code examples of your code?

                  • 7. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                    wolfgangknauf

                    Try to remove the discrimator columns in your entity bean.

                    You will only need this on your base class bean:

                    @Entity
                    @Inheritance(strategy=InheritanceType.SINGLE_TABLE)


                    In your subclasses, you need this:
                    @Entity
                    @DiscriminatorValue(value="blahblah")


                    If this simple approach is running, you should try to add a property for the column once again.

                    Wolfgang

                    • 8. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                      lpmon

                      As I suspected this did not work. How would the container know the coulmn and the type to apply the discriminator value to if you omit the @DiscriminatorColumn?

                      It seems to be complaining about a property named "connected". My entity has no such property?

                      I see many examples like what I am trying to do yet I cannot get mine to work.

                      If I leave out @DiscriminatorColumn

                      I get:

                      09:47:47,243 WARN [ServiceController] Problem starting service persistence.units:ear=shockwatch.ear,jar=shockwatch.jar,unitName=shockwatch
                      javax.persistence.PersistenceException: org.hibernate.PropertyNotFoundException: Could not find a setter for property connected in class com.shockwatch.server.FMPUnit
                      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
                      at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
                      at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                      at java.lang.reflect.Method.invoke(Unknown Source)
                      at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:102)
                      at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                      at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                      at java.lang.reflect.Method.invoke(Unknown Source)
                      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                      at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                      at $Proxy0.start(Unknown Source)
                      at org.jboss.system.ServiceController.start(ServiceController.java:417)
                      at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                      at java.lang.reflect.Method.invoke(Unknown Source)

                      ......
                      Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property connected in class com.shockwatch.server.FMPUnit
                      at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:216)
                      at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:209)
                      at org.hibernate.mapping.Property.getSetter(Property.java:277)
                      at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:251)
                      at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:126)
                      at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:55)
                      at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.(EntityEntityModeToTuplizerMapping.java:56)
                      at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:295)
                      at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:434)
                      at org.hibernate.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:109)
                      at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
                      at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:226)
                      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
                      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
                      ... 145 more

                      • 9. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                        lpmon

                        Here is a JBoss example: http://labs.jboss.com/jbossejb3/docs/tutorial/singleinheritance/single.html

                        The only difference between this example and mine is my discriminator column is INTEGER. If I use the approach and annotations from example I get:

                        javax.persistence.PersistenceException: org.hibernate.MappingException: Repeated column in mapping for entity: com.shockwatch.dbfacade.SWUnit column: hwModel (should be mapped with insert="false" update="false")
                        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
                        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
                        at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                        at java.lang.reflect.Method.invoke(Unknown Source)
                        at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:102)
                        at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                        at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                        at java.lang.reflect.Method.invoke(Unknown Source)
                        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                        at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                        at $Proxy0.start(Unknown Source)

                        Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.shockwatch.dbfacade.SWUnit column: hwModel (should be mapped with insert="false" update="false")
                        at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:652)
                        at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:674)
                        at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
                        at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:450)
                        at org.hibernate.mapping.SingleTableSubclass.validate(SingleTableSubclass.java:43)
                        at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
                        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
                        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)


                        And: If I change to insertable=false, updatable=false as the error suggests I cannot insert new rows!

                        • 10. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                          itsme

                          So the parents class code would look like this:

                          @Entity
                          @Table(name = "ALL_IN_ONE_TABLE")
                          @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
                          @DiscriminatorColumn(
                           name = "CHILD_TYPE",
                           discriminatorType = DiscriminatorType.INTEGER
                          )
                          public class ParentClass {
                          
                           @Id @GeneratedValue
                           private long id;
                           //common shared member for all children
                          }
                          

                          while the childrens code look like this:
                          @Entity
                          @DiscriminatorValue("1")
                          public class FirstChildren extends Parent {
                          
                           //children specific member
                          
                          }
                          

                          Note that the given discriminator value is a string.

                          • 11. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                            lpmon

                            This is identical to my approach. I am using INTEGER type also.

                            What version of JBoss and Hibernate are you using? You can look into the Hibernate manifest.MF file under the META_INF folder in the jar if you are unsure

                            I have versions:

                            hibernate-entitymanager.jar 3.2.0.GA
                            hibernate-annotations.jar 3.2.0.GA
                            hibernate3.jar 3.2.3.ga

                            • 12. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                              itsme

                              And don't forget:
                              do not name a field in childrens class like the column for the discriminator is named. Just annotate the childrens class as mentioned above.

                              • 13. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                                itsme

                                jboss 4.2.2GA
                                hibernate3.jar 3.2.4sp1
                                hibernate-annotations.jar 3.2.1.GA
                                hibernate-entitymanager.jar 3.2.1.GA

                                • 14. Re: Anyone have SINGLE_TABLE Entity inheritance working?
                                  lpmon

                                  I installed JBoss AS 4.2.2 which contained the Hibernate version itsme listed. Still the same problem!

                                  Repeated column in mapping for entity: com.shockwatch.dbfacade.SWUnit column: hwModel (should be mapped with insert="false" update="false")

                                  I have other issues with a move to 4.2.2 since I am using Seam and 4.2.2 changed to Sun's JSF. That can be solved with some reconfiguration.

                                  This is bizarre. I think I am going to get the Hibernate source and run in debug and maybe mod it depending on what I find.

                                  1 2 Previous Next