Announcement Announcement Module
Collapse
No announcement yet.
getting UncategorizedDataAccessException instead of DataIntegrityViolationException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • getting UncategorizedDataAccessException instead of DataIntegrityViolationException

    I am working on one project which i am using hibernate to access database.. I am trying to insert data in one table which has one primary key.. env_name

    table defn,
    -------------------
    component_name varchar(6) not null,
    env_name varchar(6) not null,
    env_physical_host varchar(20) not null,
    env_virtual_host varchar(20) not null,
    env_description varchar(100) not null,
    constraint env_pk PRIMARY KEY CLUSTERED (env_name)
    -------------------

    my hibernate xml file (EcrEnvironment.hbm.xml)
    ------------------------
    <hibernate-mapping package="com.ssc.ecr.maint.model.businessobject">
    <class name="EcrEnvironment" table="ecr_environment">

    <id name="envName" column="env_name" length="6"></id>
    <property name="componentName" column="component_name" length="6" not-null="true"/>
    <property name="envPhysicalHost" column="env_physical_host" length="20" not-null="true" />
    <property name="envVirtualHost" column="env_virtual_host" length="20" not-null="true"/>
    <property name="envDescription" column="env_description" length="100" not-null="true"/>
    </class>


    </hibernate-mapping>
    ----------------------------------------

    EcrEnvironment.java is name of corresponding bean object class


    now when i try to insert any row using user interface which violates this primary key i should get DataIntegrityViolationException but instead i am getting UncategorizedDataAccessException. now as per requirement i need to show vendor specific error code to user... Please help me in this regard..

    My submit method inside bean
    --------------------------

    public String submit() {

    String status = "";

    try {

    EcrEnvironment ecrenvironment =new EcrEnvironment();
    ecrenvironment.setComponentName(this.getComponentN ame());
    ecrenvironment.setEnvName(this.getEnvName());
    ecrenvironment.setEnvPhysicalHost(this.getEnvPhysi calHost());
    ecrenvironment.setEnvVirtualHost(this.getEnvVirtua lHost());
    ecrenvironment.setEnvDescription(this.getEnvDescri ption());
    System.out.println("\n\n\n BEFORE INSERT IN BEAN \n\n");
    this.getEcrEnvironmentService().saveEcrEnvironment (ecrenvironment);
    System.out.println("\n\n\n AFTER EFORE INSERT IN BEAN \n\n");
    status = "success";
    setMsg("Row inserted Successfully. Add Another");
    }
    catch (DataIntegrityViolationException e) {
    status = "error";
    setMsg("Error occurred. Try again Intigrity");
    System.out.println("error = " + status);
    }catch ( UncategorizedDataAccessException e) {

    //e.printStackTrace();

    status = "error";

    setMsg("Error occurred. Try again Unrecognized");

    System.out.println("error = " + status);
    }

    catch (DataAccessException e) {
    status = "error";
    setMsg("Error occurred. Try again DataAccess");
    System.out.println("error = " + status);
    }catch (Exception e) {
    status = "error";
    setMsg("Error occurred. Try again");
    System.out.println("error = " + status);
    }
    return status;

    }
    ---------------------

    my service layer Implementation class

    public EcrEnvironment saveEcrEnvironment(EcrEnvironment ecrEnvironment) throws RelViolationException,EnvGenericException{


    try {
    System.out.println("\n\n\n BEFORE INSERT IN SERVICE \n\n");
    EcrEnvironment newEcrEnvironment = this.ecrEnvironmentDao.saveEcrEnvironment(ecrEnvir onment);
    //Session.this.flush();
    System.out.println("\n\n\n after INSERT IN SERVICE \n\n");
    return newEcrEnvironment;
    } catch (DataIntegrityViolationException de) {
    String msg = "Could not save entity , duplicate entity id";
    this.logger.error(msg, de);
    System.out.println("\n\n\n exception data violation method od service \n\n");
    throw new RelViolationException(msg, de);
    } catch (Exception e) {
    System.out.println("\n\n\n exception method od service \n\n");
    this.logger.error(msg, e);

    throw new EnvGenericException(msg, e);
    }
    }
    ----------------------------

    my dao class save method
    ---------------------------
    public EcrEnvironment saveEcrEnvironment(EcrEnvironment ecrEnvironment) throws DataAccessException {
    System.out.println("\n\n\n BEFORE INSERT IN DAO \n\n");
    this.getHibernateTemplate().save(ecrEnvironment);
    //Session.this.flush();
    System.out.println("\n\n\n AFTER INSERT IN DAO \n\n");
    return ecrEnvironment;
    }

    public List getAllTranslationData() throws DataAccessException {
    return (List)getHibernateTemplate().execute(new HibernateCallback() {
    public Object doInHibernate(Session session) throws HibernateException, SQLException {

    //session.beginTransaction();
    List result = new ArrayList();
    result = session.createQuery("from Translation").list();
    return result;
    }
    });
    }
    ------------------------------------------------

    now i am getting following output on console...

    BEFORE INSERT IN SERVICE
    BEFORE INSERT IN DAO
    AFTER INSERT IN DAO
    after INSERT IN SERVICE

    11:35:19,621 DEBUG JDBCTransaction:103 - commit
    11:35:19,636 DEBUG SQL:393 - insert into ecr_environment (component_name, env_physical_host, env_virtual_host, env_description, env_name) values (?, ?, ?, ?, ?)
    Hibernate: insert into ecr_environment (component_name, env_physical_host, env_virtual_host, env_description, env_name) values (?, ?, ?, ?, ?)
    11:35:20,027 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: JZ0BE
    11:35:20,027 ERROR JDBCExceptionReporter:72 - JZ0BE: BatchUpdateException: Error occurred while executing batch statement: Attempt to insert duplicate key row in object 'ecr_environment' with unique index 'env_pk'

    11:35:20,027 WARN JDBCExceptionReporter:71 - SQL Error: 2601, SQLState: 23000
    11:35:20,027 ERROR JDBCExceptionReporter:72 - Attempt to insert duplicate key row in object 'ecr_environment' with unique index 'env_pk'

    11:35:20,027 WARN JDBCExceptionReporter:71 - SQL Error: 3621, SQLState: 01ZZZ
    11:35:20,058 ERROR JDBCExceptionReporter:72 - Command has been aborted.

    11:35:20,058 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
    org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
    at org.hibernate.exception.SQLStateConverter.handledN onSpecificException(SQLStateConverter.java:103)
    at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:91)
    at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:43)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:249)


    I am confused... please help me how to get proper exception in this.


    Regards
    Swapnil

  • #2
    It would really help to wrap this in [code] [ /code] tags to make it readable.
    http://www.springframework.org/docs/...tionTranslator
    Last edited by karldmoore; Aug 27th, 2007, 03:55 PM.

    Comment

    Working...
    X