1

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>

6
  • did you select the Oracle dialect for Hibernate? Commented Jul 19, 2013 at 5:57
  • 1
    can you post your hibernate configuration file? Commented Jul 19, 2013 at 6:05
  • Hi, there is no hibernate config, only JPA config. I just attach it. It is originally produced by Spring Roo Commented Jul 19, 2013 at 6:58
  • 1
    I end up doing it as follow: @Column(name = "activate_customer", columnDefinition = "NUMBER(1)") private Boolean activateCustomer; This may not be the best solution but it works. What I consider the best is if Hibernate JPA can generate correct DDL without any extra annotation since it knows it is for Oracle. Commented Jul 19, 2013 at 10:51
  • Looks like you're using 11g shouldn't your dialect be 'org.hibernate.dialect.Oracle10gDialect' ? 'org.hibernate.dialect.OracleDialect' is for Oracle 8. Commented Jul 19, 2013 at 11:27

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

try using :

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

1 Comment

That will produce db field "activate_customer TINYINT" and error is produced: "ORA-00902: invalid datatype (0 rows affected)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.