java2009eye
2009-01-08 10:55
浏览 230
已采纳

Hibernate错误!!!急---

package com.text.person;

/**

  • Person POJO类
  • */ public class Person { //设置Person类的基本属性. private String id; private String name; private String password; private String email; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }

-------------------------Person.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">
















package com.text.person;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**

  • 具体操作Hibernate方法.
  • 包括:增加,删除,修改,按ID指定查询,查询全部及模糊查询.
  • */
    public class PersonOperate {

    private Session session=null;

    /**

    • 在构造方法中去实例化session对象.
    • */
      public PersonOperate()
      {

      Configuration config=new Configuration().configure();

      SessionFactory factory=config.buildSessionFactory();

      this.session=factory.openSession();
      }

    //新增
    public void insert(Person p)
    {
    Transaction tran=this.session.beginTransaction();

    this.session.save(p);
    
    tran.commit();
    

    }

}
--------------------------测试类--------------------------------
package com.text.person;

import java.util.Iterator;
import java.util.List;

public class TestPerson {

/**
 * @param args
 */
public static void main(String[] args) {
    Person p=new Person();
    p.setId("1");
    p.setName("wuqiuming");
    p.setPassword("123456");
    p.setEmail("wuqiuming@163.com");

    PersonOperate po=new PersonOperate();
    po.insert(p);

}
--------------------------错误如下----------------------------------------

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.text.person.PersonOperate.insert(PersonOperate.java:46)
at com.text.person.TestPerson.main(TestPerson.java:19)
Caused by: java.sql.BatchUpdateException: ORA-01401: inserted value too large for column

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8738)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 9 more

[b]问题补充:[/b]
package com.text.person;

/**

  • Person POJO类
  • */ public class Person { //设置Person类的基本属性. private String id; private String name; private String password; private String email; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }

-------------------------Person.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">
















package com.text.person;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**

  • 具体操作Hibernate方法.
  • 包括:增加,删除,修改,按ID指定查询,查询全部及模糊查询.
  • */
    public class PersonOperate {

    private Session session=null;

    /**

    • 在构造方法中去实例化session对象.
    • */
      public PersonOperate()
      {

      Configuration config=new Configuration().configure();

      SessionFactory factory=config.buildSessionFactory();

      this.session=factory.openSession();
      }

    //新增
    public void insert(Person p)
    {
    Transaction tran=this.session.beginTransaction();

    this.session.save(p);
    
    tran.commit();
    

    }

}
--------------------------测试类--------------------------------
package com.text.person;

import java.util.Iterator;
import java.util.List;

public class TestPerson {

/**
 * @param args
 */
public static void main(String[] args) {
    Person p=new Person();
    p.setId("1");
    p.setName("wuqiuming");
    p.setPassword("123456");
    p.setEmail("wuqiuming@163.com");

    PersonOperate po=new PersonOperate();
    po.insert(p);

}
--------------------------错误如下----------------------------------------

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.text.person.PersonOperate.insert(PersonOperate.java:46)
at com.text.person.TestPerson.main(TestPerson.java:19)
Caused by: java.sql.BatchUpdateException: ORA-01401: inserted value too large for column

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8738)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 9 more

数据库用的是Oracle
CREATE TABLE person
{
id varchar(32) not null primary key,
name varchar(20) not null,
password varchar(20) not null,
email varchar(30)
};

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • bohemia 2009-01-08 10:57
    已采纳

    [quote]Caused by: java.sql.BatchUpdateException: ORA-01401: inserted value too large for column [/quote]

    插入的列过大;

    [quote]




    [/quote]

    你的 PASSWORD 声明长度是2;
    但你传递了6位:)
    [quote]p.setPassword("123456"); [/quote]

    点赞 打赏 评论
  • iteye_162 2009-01-08 10:58

    [color=red]inserted value too large for column [/color]
    输入值超过最大长度

    点赞 打赏 评论

相关推荐 更多相似问题