7 Replies Latest reply on May 8, 2008 1:37 PM by neilson

    MappingException: Repeated column in mapping for entity w/SI

    lpmon

      JBoss 4.0.5.GA w/EJB3 and Hibernate 3.2.3.ga (I think this is Hibernate version )

      I am trying to use entity inheritance. I have followed JBoss examples.

      If I don't put updatable=false, insertable=false on the discriminator column I get this error at deployment time:

      19:04:43,113 WARN [ServiceController] Problem starting service persistence.units:ear=mixseam.ear,jar=mixseam.jar,unitName=mixseam
      javax.persistence.PersistenceException: org.hibernate.MappingException: Repeated column in mapping for entity: com.moretolike.ejb3.entity.VideoTrack column: trackType (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)
      ....
      ....

      Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.moretolike.ejb3.entity.VideoTrack column: trackType (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)


      If use: updatable=true, insertable=true I get this error on an insert:

      20:43:29,020 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 22001
      20:43:29,020 ERROR [JDBCExceptionReporter] Data truncation: Data too long for column 'trackType' at row 1
      20:43:29,020 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.DataException: Could not execute JDBC batch update
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)


      I am guessing that I really need updatable and insertable as true and when false it yields this last error. What is the deal here? I am following examples. Is there a bug related to this?

        • 1. Re: MappingException: Repeated column in mapping for entity
          lpmon

          Title was chopped:

          ended with:

          w/SINGLE_TABLE inheritance

          • 2. Re: MappingException: Repeated column in mapping for entity
            lpmon

            Can anyone confirm they have seen this work? I just followed examples but cannot get it to work.

            If you have it working please specify which versions of JBoss and Hibernate

            • 3. Re: MappingException: Repeated column in mapping for entity

              You do not need to define the discriminator column at all. It doesn't even have to have a getter/setter.

              Regards

              Felix

              • 4. Re: MappingException: Repeated column in mapping for entity
                lpmon

                Felix,

                So how is the EJB subsystem going to know which class to return if I don't use a discriminator column?

                I tried removing the discriminator as you suggested, knowing it would not work, and as I thought it did not work. I get the error below with no discriminator column in any of the classes. I previously only declared the discriminator column on the base class and used @DescriminatorValue in the subclasses. That is how I cofigured when I started this thread/post.


                Error returned:

                Could not find a setter for property connected in class com.tester.server.FMPUnit

                Partial stack trace:

                16:04:56,352 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.tester.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)
                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.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                at $Proxy69.start(Unknown Source)
                ... MORE...


                FYI: This is a different app so the class names don't match my original post.

                • 5. Re: MappingException: Repeated column in mapping for entity
                  eyalhayun

                  did u managed to work it out?
                  im getting the same error ,,, :(

                  • 6. Re: MappingException: Repeated column in mapping for entity
                    lpmon

                    I had to hack to Hibernate core to make this work. I changed the line that throws the exception to just issue a warning and I can now read rows successfully. The proper class is returned based on the discriminator column value as expected.

                    This must be a bug as I definitely do no have duplicated column names. My class has a lot of transients. Maybe that is somehow tripping up the validation of the class.

                    However: when I try to insert a row using EJB3 I get an error. I have not fully researched this but it looks like Hibernate is adding an additional column to the insert statement it generates.

                    I get : Caused by: java.sql.SQLException: Parameter index out of range (14 > number of parameters, which is 13)

                    My table has 14 columns + primary key = 15 total. I dont think the Hibernate insert uses the primary key column. Guessing about that then it should insert 13 columns but appears to be adding another with some large integer value.

                    I am about to reembark on solving this problem.

                    Of note: someone in the Hibernate forum suggested removing the discriminator column. Seemed strange to me. How would one know what class to build when retrieving the column? Tried it anyway. Did not work.

                    • 7. Re: MappingException: Repeated column in mapping for entity
                      neilson

                      Hello folks,
                      In fact, you should not define an extra class attribute for the discriminator column. Probably this is the cause of your error.
                      So, your class might look like this:

                      @Entity @Table(name="products")
                      @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
                      @DiscriminatorColumn(name="type_product")
                      public class Product implements Serializable {
                       private String field1;
                       private String field2;
                       ...
                       //No typeProduct attribute here!!!!
                      
                      }


                      And then, in your Product based class(es) (EletronicProduct for instance), you would have:

                      @Entity @DiscriminatorValue("E")
                      public class ElectroProduct extends Product {
                      
                       private String field1;
                      ...
                      }


                      I was having a similar error but using the "Joined-Subclass" approach.
                      After reading your posts I found out that I really had a repeated column, but It was not that obvious because it was coming by inheritance. So, in this case, you shouldn't create "Id" attributes for your based classes because they already inherit one from the base class. That's when I was getting the "Repeated column in mapping for entity".
                      FYI, my classes look like these (doing in the "Joined-Subclass" way):

                      @Entity @Table(name="products")
                      @Inheritance(strategy=InheritanceType.JOINED)
                      public abstract class Product implements Serializable {
                       protected Integer id;
                       protected String name;
                      ...
                      }


                      @Entity @Table(name="products_category1")
                      @PrimaryKeyJoinColumn(name="idCat1", referencedColumnName="id")
                      public class ProductsCategory1 extends Products implements Serializable {
                       @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
                       private Long idCat1;
                       @Column(name="field1")
                       private double field1;
                       ...
                      }
                      

                      @Entity @Table(name="products_category2")
                      @PrimaryKeyJoinColumn(name="idCat2", referencedColumnName="id")
                      public class ProductsCategory2 extends Products implements Serializable {
                       @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
                       private Long idCat2;
                       @Column(name="field1")
                       private double field1;
                       ...
                      }



                      So. as inheritance concept says, ProductCategory1 and ProductCategory1 will inherit "id" attribute and thus,
                      the lines
                      @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
                       private Long idCat1;


                      and

                      @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
                       private Long idCat2;


                      will cause this problem to occur.


                      I hope I have helped

                      Neilson