Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

catch java exception in flex


Level 1


in my pojo i have one object

@Column(name = "GRUPO", unique = true, nullable = false, length = 45)

public String getGrupo() {
        return this.grupo;

then i have a DAO Class to save object in database like this

public void save(Gruposdeusuarios entity) {
        EntityManagerHelper.log("saving Gruposdeusuarios instance", Level.INFO,
        try {
            EntityManagerHelper.log("save successful", Level.INFO, null);           
        } catch (RuntimeException re) {
            EntityManagerHelper.log("save failed", Level.SEVERE, re);
            throw re;

then i have AbstractAssembler to make a call from flex to dao

public void createItem(Object entity){
        GruposdeusuariosDAO dao = new GruposdeusuariosDAO();
        dao.save((Gruposdeusuarios) entity);

if i duplicate de object i get this exception

GRAVE: save failed
javax.persistence.RollbackException: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'ENELDO' for key 'GRUPO'
Error Code: 1062
Call: INSERT INTO mydaniel.gruposdeusuarios (GRUPO) VALUES (?)
    bind => [ENELDO]

the question is

how i can catch the Error Code:1062 and Duplicate Key Name "GRUPO" to flex dataservice on fault to tell flex user it trying to duplicate value

i using Tomcat 6 , Livecycle Data Service 2.5, mysql-connector-java-5.1.8-bin, JPA Toplink and Flex Builder 3.3


2 Replies


Level 3


    First me not Clear wether you are using HttpService/Remote Objects.

    If you are using Remote Object Just go with the Following Link.


    If the Case you are using HttpService then while Returning the Result append the Message in the Headers

      for example return an xml like this

       <result status="true" message="Exception Here" >

               <item name="...........">

               <item name="...........">


   And everyTime check wether status is true or false if status=false then display the Message.


Level 1

Thanks for your response

i Not using HttpService or Remote Objects.i using DataService Component on flex conecting to java using LiveCycle Data Service with Adstracassamabler