[jboss-user] [EJB 3.0] - Re: MappingException: Repeated column in mapping for entity

neilson do-not-reply at jboss.com
Thu May 8 13:37:47 EDT 2008


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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4149532#4149532

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4149532



More information about the jboss-user mailing list