0
@ManyToMany
@JoinTable(schema = "cust_tables", joinColumns = @JoinColumn(name = "item_id"))
public Map<Attribute, Option> attributeValues;

Attribute 是属性名称,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”。我该如何指定?

4

1 回答 1

1

要更改列 Attribute 的名称,请尝试使用注解 @MayKeyJoinColumn。像这样的东西:

@ManyToMany
@JoinTable(schema = "cust_tables", joinColumns = @JoinColumn(name = "item_id"))
@MapKeyJoinColumn(name="ATTRIBUTE")
public Map<Attribute, Option> attributeValues;
于 2013-02-08T09:19:49.087 回答