gpt4 book ai didi

java - 从实体生成表

转载 作者:太空宇宙 更新时间:2023-11-04 07:12:42 24 4
gpt4 key购买 nike

使用 Hibernate 工具,我想生成一个脚本来从我的 java 项目中的实体创建表。你知道怎么做吗?

import java.io.Serializable; 
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "foo")
public class Foo implements Serializable {

private static final long serialVersionUID = 1L;
@Id
private int userId;
@Id
private int number;

public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number= number;
}
}

我正在尝试这个非常简单的例子

最佳答案

这样做

    String[] s = config.generateSchemaCreationScript(new PostgreSQL82Dialect());
StringBuilder script = new StringBuilder();
Formatter formatter = FormatStyle.DDL.getFormatter();
for (int i = 0; i < s.length; i++) {
String line = formatter.format(s[i]);
script.append(line);
script.append(";\n");
}
System.out.println(script.toString());

关于java - 从实体生成表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20425189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com