eclipselink tries to execute the following statement against a postgresql database:

CREATE TABLE inventory.item (ID BIGINT NOT NULL, AVAILABLEUNITS BIGINT, NAME VARCHAR(255), VERSION SMALLINT NOT NULL, ID BIGINT NOT NULL, NAME VARCHAR(255), PRICE DECIMAL(38), VERSION SMALLINT NOT NULL, PRIMARY KEY (ID, ID))

The error message from postgresql is:

org.postgresql.util.PSQLException: ERROR: column "id" appears twice in primary key constraint

I do not see why eclipselink generates a statement with a duplicate column. Here is the entity bean:

@Entity
@Table(name = "item", schema = "inventory")
public class InventoryItemJPA extends AbstractEntity implements InventoryItem
{
    private String name;
    private Long   availableUnits;

    public InventoryItemJPA(String name, Long availableUnits)
    {
        this.name           = name;
        this.availableUnits = availableUnits;
    }

    public InventoryItemJPA(InventoryItem item)
    {
        id             = item.id();
        name           = item.name();
        availableUnits = item.availableUnits();
    }
...
}

The fields ìd and version are defined in AbstractEntity:

public abstract class AbstractEntity implements Entity<Long>
{
    @Id @GeneratedValue protected Long id;

    @Version @Column(nullable = false)
    protected Short version;
...
}

Something else: There is another table called Item in another schema on the postgresql database. It has a field primary field called id, too.

What am I supposed to do to avoid this?

0

There are 0 best solutions below