英文:
How to use `@CollectionTable` with JPA Buddy
问题
我尝试使用JPA Buddy生成Liquibase初始化Changelog。
不知何故,JPA Buddy正在忽略使用@CollectionTable声明的表。这是JPA Buddy没有覆盖的功能吗?
这是我的定义:
@ElementCollection(targetClass = CareerLevel.class)
@Enumerated(EnumType.STRING)
@CollectionTable(name = "inventory_bundle_career_level",
joinColumns = {@JoinColumn(name = "inventory_bundle_id", columnDefinition = "CHAR(36)")})
@Column(name = "career_level", columnDefinition = "VARCHAR(50)")
private List<CareerLevel> careerLevel = new ArrayList<>();
英文:
I try to generate a Liquibase init Changelog with JPA Buddy.
Somehow, JPA Buddy is ignoring tables declared with @CollectionTable. Is it a feature that JPA Buddy does not cover?
Here is my definition:
@ElementCollection(targetClass = CareerLevel.class)
@Enumerated(EnumType.STRING)
@CollectionTable(name = "inventory_bundle_career_level",
joinColumns = {@JoinColumn(name = "inventory_bundle_id", columnDefinition = "CHAR(36)")})
@Column(name = "career_level", columnDefinition = "VARCHAR(50)")
private List<CareerLevel> careerLevel = new ArrayList<>();
答案1
得分: 2
我正在使用 JPA Buddy 的最新版本:2023.2.3,并且 JPA Buddy 正确为 @CollectionTable 生成表格。例如,我根据您提供的代码片段创建了以下模型:
@Entity
@Table(name = "inventory_bundle")
public class InventoryBundle {
@Id
@Column(name = "id", columnDefinition = "CHAR(36)")
private String id;
@ElementCollection(targetClass = CareerLevel.class)
@Enumerated(EnumType.STRING)
@CollectionTable(
name = "inventory_bundle_career_level",
joinColumns = {
@JoinColumn(name = "inventory_bundle_id", columnDefinition = "CHAR(36)")
})
@Column(name = "career_level", columnDefinition = "VARCHAR(50)")
private List<CareerLevel> careerLevel = new ArrayList<>();
}
public enum CareerLevel {
ENTRY_LEVEL,
JUNIOR,
MID_LEVEL,
SENIOR,
EXECUTIVE
}
而 JPA Buddy 为它生成了以下脚本:
CREATE TABLE inventory_bundle
(
id CHAR(36) NOT NULL,
CONSTRAINT pk_inventory_bundle PRIMARY KEY (id)
);
CREATE TABLE inventory_bundle_career_level
(
inventory_bundle_id CHAR(36) NOT NULL,
career_level VARCHAR(50)
);
ALTER TABLE inventory_bundle_career_level
ADD CONSTRAINT fk_inventory_bundle_career_level_on_inventory_bundle FOREIGN KEY (inventory_bundle_id) REFERENCES inventory_bundle (id);
这个脚本与 Hibernate ddl-auto 生成的内容完全匹配。也许您的模型有些许不同?如果您能提供更详细的情况描述,我将不胜感激,这样我就可以进一步检查它了。 😊
英文:
Which version of JPA Buddy are you using?
I'm using the latest version of JPA Buddy: 2023.2.3 and JPA Buddy generates a table for @CollectionTable correctly. For example, I created the following model based on the code snippet you provided:
@Entity
@Table(name = "inventory_bundle")
public class InventoryBundle {
@Id
@Column(name = "id", columnDefinition = "CHAR(36)")
private String id;
@ElementCollection(targetClass = CareerLevel.class)
@Enumerated(EnumType.STRING)
@CollectionTable(
name = "inventory_bundle_career_level",
joinColumns = {
@JoinColumn(name = "inventory_bundle_id", columnDefinition = "CHAR(36)")
})
@Column(name = "career_level", columnDefinition = "VARCHAR(50)")
private List<CareerLevel> careerLevel = new ArrayList<>();
}
public enum CareerLevel {
ENTRY_LEVEL,
JUNIOR,
MID_LEVEL,
SENIOR,
EXECUTIVE
}
And JPA Buddy generated the following script for it:
CREATE TABLE inventory_bundle
(
id CHAR(36) NOT NULL,
CONSTRAINT pk_inventory_bundle PRIMARY KEY (id)
);
CREATE TABLE inventory_bundle_career_level
(
inventory_bundle_id CHAR(36) NOT NULL,
career_level VARCHAR(50)
);
ALTER TABLE inventory_bundle_career_level
ADD CONSTRAINT fk_inventory_bundle_career_level_on_inventory_bundle FOREIGN KEY (inventory_bundle_id) REFERENCES inventory_bundle (id);
This script matches exactly what Hibernate ddl-auto generates. Maybe your model is slightly different? I would appreciate a more detailed description of the case so that I can check it out 🙂
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论