我正在尝试使用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-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>
休眠Scenariste表映射文件:
<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>
SCENARISTE表如下所示:
我还在数据库中触发了一个触发器,以增加ID_SCENARISTE列。
运行此代码时,出现以下错误:ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
以下是发生错误时Hibernate日志的最后几行:
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
我正在使用Hibernate 3.2.0.cr5和Java SE 8。
您有解决方案吗?
答案 0 :(得分:0)
尝试删除这样的数据类型
<id name="idScenariste" column="ID_SCENARISTE" unsaved-value="0">
<generator class="sequence">
<param name="sequence">SEQ_SCENARISTE</param>
</generator>
</id>