gpt4 book ai didi

java - hibernate SchemaExport 工具无法导出模式并创建奇怪的 sql 查询,甚至在 sql 命令行实用程序上失败

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

我正在通过另一个实用程序手动创建模式并且成功。

我正在使用 config xml 在其他地方创建 session 工厂。

当我尝试运行架构导出时,它在日志中给出了一个奇怪的错误,例如

13:18:33,932 ERROR SchemaExport:386 - Unsuccessful: create table entitydef (id bigint not    null auto_increment unique, hbmfile LONGTEXT, isExported tinyint not null, name varchar(50), schemaId bigint, typeId bigint, primary key (id)) type=InnoDB

我尝试在 sql workbench 上运行查询,当我删除 type=InnoDB 部分时它会起作用。

这里出了什么问题?为了简洁起见,我删除了其余的 pojo 定义。

我创建了一个包含以下内容的 hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">**********</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dev_org_appops_entitystore_0_0_1</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="javax.persistence.validation.mode">none</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="default_entity_mode">POJO</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>


<!-- this is c3p0 configuration -->
<property name="org.hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.connection.autoReconnect">true</property>
<property name="hibernate.c3p0.acquire_increment">3</property>
<property name="hibernate.c3p0.max_size">50</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.min_size">0</property>
<property name="hibernate.c3p0.timeout">5</property>

<!--ehcache configuration-->

<mapping class="org.appops.entityStore.hibernate.dao.domain.Entitydef"/>
<mapping class="org.appops.entityStore.hibernate.dao.domain.Property"/>
<mapping class="org.appops.entityStore.hibernate.dao.domain.Propertydef"/>
<mapping class="org.appops.entityStore.hibernate.dao.domain.Schemadef"/>
<mapping class="org.appops.entityStore.hibernate.dao.domain.Types"/>
<mapping class="org.appops.entityStore.hibernate.dao.domain.QueryDef"/>
<mapping class="org.appops.entityStore.hibernate.dao.domain.QueryParamType"/>

</session-factory>

</hibernate-configuration>

我已经注释了 pojo,如下所示

@Entity
@Table(name = "entitydef")
public class Entitydef implements java.io.Serializable {

private Long id;
private String name;
private Long typeId;
private Long schemaId;
private String hbmfile;
private byte isExported;

public Entitydef() {
}

public Entitydef(final byte isExported) {
this.isExported = isExported;
}

public Entitydef(final String name, final Long typeId, final Long schemaId, final String hbmfile,
final byte isExported) {
this.name = name;
this.typeId = typeId;
this.schemaId = schemaId;
this.hbmfile = hbmfile;
this.isExported = isExported;
}

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return this.id;
}

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

@Column(name = "name", length = 50)
public String getName() {
return this.name;
}

public void setName(final String name) {
this.name = name;
}

@Column(name = "typeId")
public Long getTypeId() {
return this.typeId;
}

public void setTypeId(final Long typeId) {
this.typeId = typeId;
}

@Column(name = "schemaId")
public Long getSchemaId() {
return this.schemaId;
}

public void setSchemaId(final Long schemaId) {
this.schemaId = schemaId;
}

@Column(name = "hbmfile", columnDefinition = "LONGTEXT")
public String getHbmfile() {
return this.hbmfile;
}

public void setHbmfile(final String hbmfile) {
this.hbmfile = hbmfile;
}

@Column(name = "isExported", nullable = false)
public byte getIsExported() {
return this.isExported;
}

public void setIsExported(final byte isExported) {
this.isExported = isExported;
}

}

最佳答案

发现问题了。

我需要使用

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

而不是

<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

由于使用的MySql是5.0以上

关于java - hibernate SchemaExport 工具无法导出模式并创建奇怪的 sql 查询,甚至在 sql 命令行实用程序上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25781992/

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