我正在使用
public class UserTask extends BaseObject implements Serializable {
@ElementCollection(targetClass = java.lang.String.class)
private List<String> userTaskMessage = new ArrayList<>();
.
.
.
.
Hibernate生成表,名称为usertask_usertaskmessage
。
如何设置我的名字?例如my_table_example
感谢您的帮助!
答案 0 :(得分:18)
使用注释@CollectionTable(name =“your_table_name”)
答案 1 :(得分:7)
JPA:
@Entity
@Table(name = "SERVICES")
public class Service {
@Id
@Column(name = "ID")
private Long id;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "SERVICE_LINKED_CODES", joinColumns = @JoinColumn(name = "SERVICE_ID"))
@Column(name = "CODE")
private List<String> linkedCodes;
}
数据库中的架构:
CREATE TABLE SERVICES { ID BIGINT };
CREATE TABLE SERVICE_LINKED_CODES { SERVICE_ID BIGINT, CODE VARCHAR(255) };