Duplicate column name by JPA with @ElementCollection and @Inheritance

Posted by gerry on Stack Overflow See other posts from Stack Overflow or by gerry
Published on 2010-03-17T19:57:44Z Indexed on 2010/03/17 20:01 UTC
Read the original article Hit count: 424

Filed under:
|

I've created the following scenario:

@javax.persistence.Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class MyEntity implements Serializable{
    @Id
    @GeneratedValue
    protected Long id;
    ...
    @ElementCollection
    @CollectionTable(name="ENTITY_PARAMS")
    @MapKeyColumn (name = "ENTITY_KEY")
    @Column(name = "ENTITY_VALUE")
    protected Map<String, String> parameters;
    ...
}

As well as:

@javax.persistence.Entity
public class Sensor extends MyEntity{
    @Id
    @GeneratedValue
    protected Long id;
    ...

    // so here "protected Map<String, String> parameters;" is inherited !!!!
    ...
}

So running this example, no tables are created and i get the following message:

WARNUNG: Got SQLException executing statement "CREATE TABLE ENTITY_PARAMS (Entity_ID BIGINT NOT NULL, ENTITY_VALUE VARCHAR(255), ENTITY_KEY VARCHAR(255), Sensor_ID BIGINT NOT NULL, ENTITY_VALUE VARCHAR(255))": com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Duplicate column name 'ENTITY_VALUE'

I also tried overriding the attributes on the Sensor class...

@AttributeOverrides({
    @AttributeOverride(name = "ENTITY_KEY", column = @Column(name = "SENSOR_KEY")),
    @AttributeOverride(name = "ENTITY_VALUE", column = @Column(name = "SENSOR_VALUE"))
})

... but the same error.

Can anybody help me?

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa