gpt4 book ai didi

java - Hibernate不会从模型到数据库生成表

转载 作者:行者123 更新时间:2023-12-01 11:43:13 26 4
gpt4 key购买 nike

我正在尝试从模型类获取包含表的数据库,问题在于自动生成带有 Hibernate 注释的表。

我有一个名为 models-test 的 Maven 模型项目,其中有以下类(class):

@Audited
@Entity
@Table(name = "test_EXTEND", schema = "COTest")
public class ComaTest implements Serializable {

private static final long serialVersionUID = 393765467600954104L;

@Id
@Column(name = "CL_o_CODE")
private Integer id;
@Column(name = "CL_o_NUM01")
private Long refCountryCode;
@Column(name = "CL_o_STR01")
private String city;
@Column(name = "CL_o_STR02")
private String zipCode;

public Integer getId() {
return this.id;
}

public void setId(final Integer idVal) {
this.id = idVal;
}

public Long getRefCountryCode() {
return this.refCountryCode;
}
public void setRefCountryCode(final Long refCountryCode) {
this.refCountryCode = refCountryCode;
}
public String getCity() {
return this.city;
}
public void setCity(final String cityVal) {
this.city = cityVal;
}
public String getZipCode() {
return this.zipCode;
}
public void setZipCode(final String zipCodeVal) {
this.zipCode = zipCodeVal;
}
}

我有一个名为interface_test的其他项目,其中有我所有的接口(interface),然后我有第三个名为services-test的maven项目,我在persistence.xml文件中制作了:

<persistence-unit name="op_PU">
<jta-data-source>java:jboss/datasources/op_DS</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="update" />

<property name="org.hibernate.envers.audit_table_suffix"
value="_aud" />
<property name="org.hibernate.envers.revision_field_name"
value="rev" />
<property name="org.hibernate.envers.revision_type_field_name"
value="rev_type" />
</properties>
</persistence-unit>

在jboss服务器的standalone.xml中我有这个连接字符串:

<datasource jndi-name="java:jboss/datasources/op_DS" pool-name="op_DS" enabled="true" use-java-context="true">
<connection-url>jdbc:sqlserver://localhost;databaseName=OP_DB;</connection-url>
<driver>sqlserver</driver>
<security>
<user-name>sa</user-name>
<password>testpassword</password>
</security>
</datasource>

在控制台中我有:

ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 94) The specified schema name "COTest" either does not exist or you do not have permission to use it.
ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 94) HHH000389: Unsuccessful: create table COTest.test_EXTEND (CL_o_CODE int not null, CL_o_STR01 varchar(255), CL_o_STR02 varchar(255), CL_o_STR03 varchar(255), primary key (CL_o_CODE, rev)))

最佳答案

您好,我认为名为 hibernate.hbm2ddl.auto 的 persistence.xml 属性存在问题,您已为其指定了更新值,并且您需要创建或创建删除(如果是开发环境)以从模型生成表到数据库。hibernate.hbm2ddl.auto 的可能选项列表是,

validate: validate the schema, makes no changes to the database.
update: update the schema.
create: creates the schema, destroying previous data.
create-drop: drop the schema at the end of the session.

关于java - Hibernate不会从模型到数据库生成表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29344224/

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