我正在使用H2嵌入式数据库和Hibernate 5.我正在尝试以这种方式在hibernate中映射HashMap:
@Entity
public class TestMapping
{
@Id
@GeneratedValue
private Long id;
@ElementCollection
private Map<Integer,String> map = new HashMap<>();
}
然后我坚持TestMapping对象包含几个对键值。当我试图通过执行类似这样的事情来看Intellij中的结果时:
SELECT t.* FROM PUBLIC.TESTMAPPING t LIMIT 501
我收到此错误:
[23505][23505] Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement: ALTER TABLE PUBLIC.TESTMAPPING_MAP ADD CONSTRAINT PUBLIC.FK8CYRSMJWNRD21DCB8T901RHA0 FOREIGN KEY(TESTMAPPING_ID) REFERENCES PUBLIC.TESTMAPPING(ID) NOCHECK [23505-176]
我试图添加@MapKeyColumn
无效。
mydb.trace.db包含:
10-09 13:38:28 database: ALTER TABLE PUBLIC.TESTMAPPING_IMAGES ADD CONSTRAINT PUBLIC.FK9V996C496B8GCB45MJI7WDA0D FOREIGN KEY(TESTMAPPING_ID) REFERENCES PUBLIC.TESTMAPPING(ID) NOCHECK
org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement:
ALTER TABLE PUBLIC.TESTMAPPING_IMAGES ADD CONSTRAINT PUBLIC.FK9V996C496B8GCB45MJI7WDA0D FOREIGN KEY(TESTMAPPING_ID) REFERENCES PUBLIC.TESTMAPPING(ID) NOCHECK [23505-176]
10-09 13:38:29 database: ALTER TABLE PUBLIC.TESTMAPPING_IMAGES ADD CONSTRAINT PUBLIC.FK9V996C496B8GCB45MJI7WDA0D FOREIGN KEY(TESTMAPPING_ID) REFERENCES PUBLIC.TESTMAPPING(ID) NOCHECK
org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement:
ALTER TABLE PUBLIC.TESTMAPPING_IMAGES ADD CONSTRAINT PUBLIC.FK9V996C496B8GCB45MJI7WDA0D FOREIGN KEY(TESTMAPPING_ID) REFERENCES PUBLIC.TESTMAPPING(ID) NOCHECK [23505-176]