1

我尝试通过将 hibernate.hbm2ddl.auto 设置为“创建”来使用 JPA 自动创建 Oracle 表。实体字段之一是布尔类型,在 Java 中如下所示:

private boolean activateCustomer;

但是,当我们运行它时,会抛出一个错误,当我查看错误时,生成的 sql 类型是布尔值而不是 Number(1)。我使用 Hibernate 4.1.9 和 Oracle XE(文件:OracleXE112_Win32.zip)。

从我在互联网上找到的(大多数是几年前)默认情况下它应该是 Number(1)。Oracle、Hibernate 或 JPA 是否有任何改变来改变行为?

或者,有没有我错过的配置?谢谢。


JPA 配置:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
        <!-- value="create" to build a new database on each run; value="update" to modify an existing database; value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->
        <property name="hibernate.hbm2ddl.auto" value="create"/>
        <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
        <property name="hibernate.connection.charSet" value="UTF-8"/>
        <!-- Uncomment the following two properties for JBoss only -->
        <!-- property name="hibernate.validator.apply_to_ddl" value="false" /-->
        <!-- property name="hibernate.validator.autoregister_listeners" value="false" /-->
    </properties>
</persistence-unit>

4

2 回答 2

2

看起来您使用的是 11g,所以您的方言应该是org.hibernate.dialect.Oracle10gDialect,而不是org.hibernate.dialect.OracleDialect仅适用于 Oracle 8。

于 2013-07-24T16:00:55.307 回答
1

尝试使用:

@Column(columnDefinition = "TINYINT")
@Type(type = "org.hibernate.type.NumericBooleanType")
private boolean activateCustomer;
于 2013-07-19T09:05:40.780 回答