cix.yong
cix.yong

Reputation: 35

Create table using Hibernate JPA for Oracle throws error

I try to auto-create Oracle tables using JPA by setting hibernate.hbm2ddl.auto to 'create'. One of the entity field is boolean type and in Java it is like below:

private boolean activateCustomer;

However, when we run it an error is thrown and when I look at the error the generated sql type is boolean instead of Number(1). I use Hibernate 4.1.9 and Oracle XE (the file: OracleXE112_Win32.zip).

From what I found on the internet (Mostly some years old) by default it should be Number(1). Has there been any change to Oracle, Hibernate or JPA to change the behaviour?

Or, is there configuration I have missed? Thanks.


JPA configuration:

<?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>

Upvotes: 1

Views: 2983

Answers (2)

fn.
fn.

Reputation: 2936

Looks like you're using 11g so your dialect should be org.hibernate.dialect.Oracle10gDialect instead of org.hibernate.dialect.OracleDialect which is only for Oracle 8.

Upvotes: 2

fla
fla

Reputation: 143

try using :

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

Upvotes: 1

Related Questions