File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes help!!hibernate could not insert one record with oracle! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "help!!hibernate could not insert one record with oracle!" Watch "help!!hibernate could not insert one record with oracle!" New topic
Author

help!!hibernate could not insert one record with oracle!

zisheng phenix
Greenhorn

Joined: Jul 18, 2009
Posts: 6
envirment:
hibernate 3.2;
datbase oracle;
hibernateXML:

person.hbm.xml:

table:

my Test Code:


error:



Hibernate: insert into T_person (id, name) values (null, ?)
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: could not insert: [hibernate3.pojo.Person]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at test.TestSession.main(TestSession.java:21)
Caused by: java.sql.SQLException: ORA-01400: 无法将 NULL 插入 ("U_TEST"."T_PERSON"."ID")

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:33)
... 16 more

zisheng phenix
Greenhorn

Joined: Jul 18, 2009
Posts: 6
zisheng phenix
Greenhorn

Joined: Jul 18, 2009
Posts: 6
person Class

package hibernate3.pojo;

public class Person {
private Integer id;
private String name;

public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

zisheng phenix
Greenhorn

Joined: Jul 18, 2009
Posts: 6
help does not come?
zisheng phenix
Greenhorn

Joined: Jul 18, 2009
Posts: 6
This problem has been resolved.
change the hibernate.xml SQL dialect
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
ok!
Joachim Rohde
Ranch Hand

Joined: Nov 27, 2006
Posts: 423

A well-intentioned advice: read the article under http://catb.org/esr/faqs/smart-questions.html before you ask a question the next time.
zisheng phenix
Greenhorn

Joined: Jul 18, 2009
Posts: 6
Joachim Rohde wrote:A well-intentioned advice: read the article under http://catb.org/esr/faqs/smart-questions.html before you ask a question the next time.

thank you for your advice!I am studying hibernate ,you know,I am a beginner .could you give me some advice and
recommend some books,thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help!!hibernate could not insert one record with oracle!