I'm trying to map an Oracle database with Java using Hibernate but I'm facing an issue. Here is the code :
Java app :
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 config file :
<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 Scenariste table mapping file :
<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>
And the SCENARISTE table looks like that :
I also made a trigger in the database to increment the ID_SCENARISTE column.
When I run this code I have this error : ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
Here are the last lines of the Hibernate log when the error occurs :
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
I'm using Hibernate 3.2.0.cr5 and Java SE 8.
Do you have a solution ?