当前位置: 首页 > 知识库问答 >
问题:

Hibernate ORA-00932:不一致的数据类型:预期的数字是二进制的

孔永年
2023-03-14

我试图使用Hibernate用Java映射Oracle数据库,但我面临一个问题。代码如下:

Java应用程序

package guival.tp3.bdd;

import java.time.LocalDate;
import org.hibernate.*;

public class Scenariste extends Personne {
    private int idScenariste;

    public int getIdScenariste() {
        return idScenariste;
    }

    public void setIdScenariste(int idScenariste) {
        this.idScenariste = idScenariste;
    }
}

public class Test {

    public static void main(String[] args) {

        Session uneSession = HibernateUtil.getSessionFactory().openSession();
        Transaction uneTransaction = uneSession.beginTransaction();

        Scenariste scenar = new Scenariste();
        scenar.setDateNaissance(LocalDate.now());
        scenar.setNom("fefef");
        scenar.setPrenom("fefzefzfz");

        uneSession.save(scenar);

        uneTransaction.commit();
        uneSession.close();

        HibernateUtil.shutdown();
    }
}

Hibernate配置文件:

<hibernate-configuration>
    <session-factory>

        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521/system</property>
        <property name="hibernate.connection.username">---</property>
        <property name="hibernate.connection.password">---</property>

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

        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.timeout">300</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.idle_test_period">3000</property>

        <!-- SQL to stdout logging -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="use_sql_comments">true</property>

        <mapping resource="guival/tp3/bdd/Scenariste.hbm.xml"/>

    </session-factory>
</hibernate-configuration>

Hibernate场景表映射文件:

<hibernate-mapping>

    <class name="guival.tp3.bdd.Scenariste" table="SCENARISTE">

    <id name="idScenariste" column="ID_SCENARISTE" type="integer" unsaved-value="0">
            <generator class="sequence">
            <param name="sequence">SEQ_SCENARISTE</param>
            </generator>
        </id>

    <property name="nom">
        <column name="NOM" sql-type="VARCHAR2(50)"/>
    </property>

    <property name="prenom">
        <column name="PRENOM" sql-type="VARCHAR2(50)"/>
    </property>

    <property name="dateNaissance">
        <column name="DATE_NAISSANCE" sql-type="DATE"/>
    </property>

    </class>

</hibernate-mapping>

Hibernate: 
    select
        SEQ_SCENARISTE.nextval 
    from
        dual
Hibernate: 
    /* insert guival.tp3.bdd.Scenariste
        */ insert 
        into
            SCENARISTE
            (NOM, PRENOM, DATE_NAISSANCE, ID_SCENARISTE) 
        values
            (?, ?, ?, ?)
déc. 02, 2018 6:48:55 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 932, SQLState: 42000
déc. 02, 2018 6:48:55 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-00932: types de données incohérents ; attendu : NUMBER ; obtenu : BINARY

共有1个答案

蔺山
2023-03-14

尝试像这样删除数据类型

 <id name="idScenariste" column="ID_SCENARISTE" unsaved-value="0">
        <generator class="sequence">
        <param name="sequence">SEQ_SCENARISTE</param>
        </generator>
 </id>
 类似资料: