使用Hibernate创建表JPA for Oracle抛出错误

时间:2013-07-19 05:43:05

标签: java oracle hibernate jpa

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

private boolean activateCustomer;

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

从我在互联网上找到的东西(大多数是几年前)默认情况下它应该是数字(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>

2 个答案:

答案 0 :(得分:2)

看起来你正在使用11g所以你的方言应该是org.hibernate.dialect.Oracle10gDialect而不是仅仅用于Oracle 8的org.hibernate.dialect.OracleDialect

答案 1 :(得分:1)

尝试使用:

@Column(columnDefinition = "TINYINT")
@Type(type = "org.hibernate.type.NumericBooleanType")
private boolean activateCustomer;