我只是想从我的oracle sql数据库中从CONTACTS表中获取一行信息,我收到了这个错误:
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: la séquence n'existe pas (non existing sequence)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1017)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:655)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:566)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:215)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:58)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:776)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:897)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1034)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3820)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3867)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1502)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:116)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
... 12 more
Java结果:1
我的Contacts.hbm.xml文件:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Contacts" table="CONTACTS">
<id name="id_contact" type="integer" column="IDCONTACTS">
<generator class="native"/>
</id>
<property name="nom" column="NOM" type="string" length="20"/>
<property name="prenom" column="PRENOM" type="string" length="20"/>
<property name="email" column="EMAIL" type="string" length="20"/>
<property name="salaire" column="SALAIRE" type="integer" length="12"/>
</class>
</hibernate-mapping>
我的hibernate.cfg.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.Oracle10gDialect
</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">
adresse...
</property>
<property name="hibernate.connection.username">
login
</property>
<property name="hibernate.connection.password">
psswrd
</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>
<mapping class="Contacts" file="" jar="" package="" resource="Contacts.hbm.xml"/>
</session-factory>
</hibernate-configuration>
和Contacts.java
import java.io.Serializable;
public class Contacts implements Serializable {
private int id_contact;
private String nom, prenom, email;
private float salaire;
public Contacts(){
}
public int getId_contact() {
return id_contact;
}
public void setId_contact(int id_contact) {
this.id_contact = id_contact;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public float getSalaire() {
return salaire;
}
public void setSalaire(float salaire) {
this.salaire = salaire;
}
}
我打电话时发生错误
session.save(contact1)
//contact1 has been using setters to populate its fields.
我在sqlplus上的表看起来像这样
Name Null? Type
----------------------------------------- -------- ----------------------------
IDCONTACT NOT NULL NUMBER(38)
NOM VARCHAR2(20)
PRENOM VARCHAR2(20)
EMAIL VARCHAR2(20)
SALAIRE NUMBER(12)
谢谢你看看。
答案 0 :(得分:1)
我想你已经手动创建了表(没有休眠)。
由于您未在此处声明序列名称
<id name="id_contact" type="integer" column="IDCONTACTS">
<generator class="native"/>
</id>
Hibernate尝试使用名为HIBERNATE_SEQUENCE
的序列因此,您需要在数据库中创建HIBERNATE_SEQUENCE或明确定义您的序列:
<id name="id_contact" type="integer" column="IDCONTACTS">
<generator class="native">
<param name="sequence">CONTACTS_SEQ</param>
</generator>
</id>