@ManyToMany
@JoinTable(schema = "cust_tables", joinColumns = @JoinColumn(name = "item_id"))
public Map<Attribute, Option> attributeValues;
属性是属性名称,option是该属性的有效值。
EclipseLink当前为表生成以下DDL:
CREATE TABLE `items_options` (
`attributes_id` bigint(20) NOT NULL,
`item_id` bigint(20) NOT NULL,
`attributes_KEY` bigint(20) DEFAULT NULL,
PRIMARY KEY (`item_id`,`attributes_id`),
KEY `FK_items_options_attributes_id` (`attributes_id`),
KEY `FK_items_options_attributes_KEY` (`attributes_KEY`),
CONSTRAINT `FK_items_options_attributes_id` FOREIGN KEY (`attributes_id`) REFERENCES `options` (`id`),
CONSTRAINT `FK_items_options_attributes_KEY` FOREIGN KEY (`attributes_KEY`) REFERENCES `attributes` (`id`),
CONSTRAINT `FK_items_options_item_id` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
在连接表上,我需要更改列名:'attributes_id'和'attributes_KEY'。我该如何指定?
答案 0 :(得分:1)
要更改列属性的名称,请尝试注释@MayKeyJoinColumn。 像这样:
@ManyToMany
@JoinTable(schema = "cust_tables", joinColumns = @JoinColumn(name = "item_id"))
@MapKeyJoinColumn(name="ATTRIBUTE")
public Map<Attribute, Option> attributeValues;