-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Duplicate identifier in table
PostPosted: Fri Nov 26, 2010 5:00 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
HBM file code :

<class name="com.netechinc.forms.WorkDevelopmentForm.AbstractPrintForm" table="works_info">
<id name="pk_work_id">
</id>
<property name="work_name" column="work_name" type="java.lang.String"/>
<property name="vill_panch_name" column="vill_panch_name" type="java.lang.String"/>
<property name="office" column="office" type="java.lang.String"/>
<property name="constituency" column="constituency" type="java.lang.String"/>
<property name="address" type="java.lang.String" formula=" ( select w.town_vill||' , '||w.taluka||' , '||w.district||' , '||w.state||' , '||w.country||' - '||w.pin from works_info w where w.pk_work_id= pk_work_id ) "/>

<join table="abstract">
<key column="work_id"/>
<property name="est_amount" column="total_amount" type="java.lang.String"/>
</join>
</class>


When i m trying to search using this hbm file code it throws exception as

10/11/26 14:21:19 org.hibernate.HibernateException: Duplicate identifier in table for: [com.netechinc.forms.WorkDevelopmentForm.AbstractPrintForm#25]
10/11/26 14:21:19 at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1916)
10/11/26 14:21:19 at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2555)
10/11/26 14:21:19 at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2455)
10/11/26 14:21:19 at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2755)
10/11/26 14:21:19 at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:114)
10/11/26 14:21:19 at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
10/11/26 14:21:19 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:260)
10/11/26 14:21:19 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:180)
10/11/26 14:21:19 at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
10/11/26 14:21:19 at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
10/11/26 14:21:19 at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
10/11/26 14:21:19 at Hibernate.DBQueries.search(DBQueries.java:330)
10/11/26 14:21:19 at com.netechinc.actions.WorkDevelopmentAction.WorkDevelopmentAction.execute(WorkDevelopmentAction.java:149)
10/11/26 14:21:19 at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
10/11/26 14:21:19 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
10/11/26 14:21:19 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
10/11/26 14:21:19 at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:416)
10/11/26 14:21:19 at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
10/11/26 14:21:19 at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
10/11/26 14:21:19 at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719)
10/11/26 14:21:19 at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
10/11/26 14:21:19 at com.evermind.server.http.ServletRequestDispatcher.unprivileged_forward(ServletRequestDispatcher.java:270)
10/11/26 14:21:19 at com.evermind.server.http.ServletRequestDispatcher.access$100(ServletRequestDispatcher.java:42)
10/11/26 14:21:19 at com.evermind.server.http.ServletRequestDispatcher$2.oc4jRun(ServletRequestDispatcher.java:205)
10/11/26 14:21:19 at oracle.oc4j.security.OC4JSecurity.doPrivileged(OC4JSecurity.java:283)
10/11/26 14:21:19 at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:209)
10/11/26 14:21:19 at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
10/11/26 14:21:19 at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
10/11/26 14:21:19 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
10/11/26 14:21:19 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
10/11/26 14:21:19 at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:416)
10/11/26 14:21:19 at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
10/11/26 14:21:19 at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
10/11/26 14:21:19 at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719)
10/11/26 14:21:19 at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
10/11/26 14:21:19 at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
10/11/26 14:21:19 at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
10/11/26 14:21:19 at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218)
10/11/26 14:21:19 at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
10/11/26 14:21:19 at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
10/11/26 14:21:19 at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
10/11/26 14:21:19 at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230)
10/11/26 14:21:19 at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33)
10/11/26 14:21:19 at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831)



It is taking table identifier of join tag also(i.e. <join table="abstract"> )..Why is this happening and how to solve it??


Thanks in advance.
Chirag

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Mon Nov 29, 2010 7:49 am 
Beginner
Beginner

Joined: Fri Nov 26, 2010 8:25 am
Posts: 21
Hi Chirag,

Look at the stack trace, there is more than one record in the works_info table with the same work id. Take a look at your table, and the code that you use to insert and/or update it. You should find the problem there.

Kate.


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Tue Nov 30, 2010 12:23 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
But i am neither trying to insert nor update..I am trying to search data using join.

Criteria crit = session.createCriteria(form.getClass()); //Code to search result.
session.flush();

If insert or update is getting called while searching then why is it happening like this??


Thanks,
Chirag

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Tue Nov 30, 2010 5:27 am 
Beginner
Beginner

Joined: Fri Nov 26, 2010 8:25 am
Posts: 21
Hi Chirag,

The insert/update is happening when
Code:
session.flush()
is called so could you paste the rest of your code please, it will make it easier to see what might be happening if I can see all of the code run during the session!

Thanks,
Kate.


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Tue Nov 30, 2010 5:38 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
List searchresult = null;
try{
session = sessionFactory.openSession();
AlterSession(session); //Code use to alter the db timestamp and date format
Criteria crit = session.createCriteria(form.getClass()); //Creating criteria
crit.add(Restrictions.) //Adding different criteria according to requirement
searchresult = crit.list();
session.flush();
}
catch(Exception e){
}

return searchresult;

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Tue Nov 30, 2010 5:46 am 
Beginner
Beginner

Joined: Fri Nov 26, 2010 8:25 am
Posts: 21
Hi Chirag,

Next can you paste what is in AlterSession please, it will help to further narrow it down.

thanks,
Kate


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Tue Nov 30, 2010 5:51 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
public void AlterSession(org.hibernate.Session session) {

String sqlString = null;
org.hibernate.Query Query = null;
org.hibernate.Transaction tx = null;
try {

sqlString ="alter session set nls_date_format='DD/MM/YYYY'";
session.createSQLQuery(sqlString).executeUpdate();

sqlString ="ALTER SESSION SET NLS_TIMESTAMP_FORMAT='DD/MM/YYYY HH24:MI:SS'";
session.createSQLQuery(sqlString).executeUpdate();



} catch (Exception e) {
traceLogger.info(":::::Sql Session ALtered for Date::::::::");
}
traceLogger.info("******End**********");



} //End of Alter setSession

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Wed Dec 01, 2010 6:10 am 
Beginner
Beginner

Joined: Fri Nov 26, 2010 8:25 am
Posts: 21
Hi Chirag,

Do you have nullable fields in your database? If so ensure that the corresponding hibernate object fields are also marked as nullable. The nullable properties should match. If you have nullable fields in the database, but not in your object, then hibernate may mark the object as dirty so when you call Session.flush() Hibernate forces an update, even if you didnt ask for one.

Kate


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Wed Dec 01, 2010 6:29 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
k.libby wrote:
Do you have nullable fields in your database? If so ensure that the corresponding hibernate object fields are also marked as nullable. The nullable properties should match. If you have nullable fields in the database, but not in your object, then hibernate may mark the object as dirty so when you call Session.flush() Hibernate forces an update, even if you didnt ask for one.



Thanks kate,
But can you please explain with small example what you want me to do?? And how can i make hibernate object fields nullable??


Thanks in advance,
Chirag

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Wed Dec 01, 2010 6:48 am 
Beginner
Beginner

Joined: Fri Nov 26, 2010 8:25 am
Posts: 21
Hi Chirag,

Ok, to start with can you look in your database and see which fields allow null values, and which do not. You may need to find out what the default is for the database you're using. Im a bit busy at the moment but I will try to get back to you later today!

regards,
Kate.


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Thu Dec 02, 2010 12:18 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
Hi Kate..My all database field except primary key can take null-able values.

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Thu Dec 02, 2010 4:38 am 
Beginner
Beginner

Joined: Fri Nov 26, 2010 8:25 am
Posts: 21
Hi Chirag,

You posted this earlier..
Code:
List searchresult = null;
try{
session = sessionFactory.openSession();
AlterSession(session); //Code use to alter the db timestamp and date format
Criteria crit = session.createCriteria(form.getClass()); //Creating criteria
crit.add(Restrictions.) //Adding different criteria according to requirement
searchresult = crit.list();
session.flush();
}
catch(Exception e){
}

return searchresult;


Could you now post the complete section of code, exactly as it appears, including the rest of the restrictions part
Code:
crit.add(Restrictions.) //Adding different criteria according to requirement


I would also like to see the code where your variable form is created, which you use in this line:
Code:
Criteria crit = session.createCriteria(form.getClass()); //Creating criteria
is form created in the method or in the class? it is initialised at all? Could you post the whole class please. It will be easier to see what is happening if you can post all of the code that you are using.

Thanks,
Kate.


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Thu Dec 02, 2010 6:46 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
Entire class where search is performed.And form is not initiated.It is ActionForm coming from Action Class.

Business Class Code
Code:

    public List search(SessionFactory sessionFactory, ActionForm form) {

        List searchresult = null;

        try {
            AlterSession(session);
            GeneralUtils webutil = new GeneralUtils();
            HashMap temp = (HashMap)PropertyUtils.describe(form);  //Storing all data from formbean into a HashMap.
            HashMap params = webutil.validateformMap(temp); //getting parameters from Hashmap created.
            session = sessionFactory.openSession();
            AlterSession(session);
            Criteria crit = session.createCriteria(form.getClass());

            traceLogger.info("Search Result HashMap ==>" + params);

            //First Getting Date Field
            String dateFields = getS(params, "dateFields");

            String fieldName = null;
            String[] dateList = null;
            String startTag = "_from";
            String endTag = "_to";
            String startDate = null;
            String endDate = null;

            params.remove("tableName");
            params.remove("action");


            if (dateFields != null) {
                dateList = dateFields.split(",");
                for (int i = 0; i < dateList.length; i++) {
                    fieldName = dateList[i];
                    String tempFieldname = fieldName;
                    traceLogger.info("tempFieldname  " + tempFieldname);
                    startDate = getS(params, tempFieldname + startTag);
                    endDate = getS(params, tempFieldname + endTag);

                    traceLogger.info("startDate  " + startDate);
                    traceLogger.info("endDate  " + endDate);

                    params.remove(tempFieldname + startTag);
                    params.remove(tempFieldname + endTag);

                    if (startDate != null && endDate != null) {
                        if (startDate.length() == 10 &&
                            endDate.length() == 10) {

                            if(tempFieldname!=null && !tempFieldname.equalsIgnoreCase("") && tempFieldname.equalsIgnoreCase("createdate")){
                                crit.add(Restrictions.between(tempFieldname, startDate, endDate));
                            }
                            else{
                                //crit.add(Expression.sql("TO_DATE("+tempFieldname+",'DD/MM/YYYY') between '"+startDate+"' and '"+endDate+"'"));
                                crit.add(Restrictions.sqlRestriction("TO_DATE("+tempFieldname+",'DD/MM/YYYY') between '"+startDate+"' and '"+endDate+"'"));
                            }
                           

                        }
                    }
                }


            }
            params.remove("dateFields");


            // Get Order By Clause
            String orderBy = "";
            if (getS(params, "orderBy") != null) {
                orderBy = getS(params, "orderBy");
                crit.addOrder(Order.asc(orderBy));
            }
            params.remove("orderBy");
            params.remove("selTender");
            params.remove("primaryKey");
            params.remove("ad_details");


            Iterator columns = params.keySet().iterator();
            String columnName, value;
            while (columns.hasNext()) {
                columnName = (String)columns.next();
                traceLogger.info("Column Name xxx ==>" + columnName);

                // System.out.println(columnName);
                if (getS(params, columnName) != null &&
                    (getS(params, columnName)).length() > 0) {

                    traceLogger.info("Column Name ==>" + columnName);

                    value = getS(params, columnName);
                    traceLogger.info("value ==>" + value);
                    if (value != null) {
                        if (value.indexOf("'") != -1)
                            value = value.replaceAll("'", "'||chr(39)||'");
                    }

                    if (value.substring(0, 1).equals("!")) {
                        crit.add(Restrictions.ne(columnName,
                                                 value.substring(1, value.length())));
                        //fieldClause += "("+columnName +" != '"+ value.substring(1, value.length()) + "')";
                    }

                    else if (value.substring(0, 1).equals(">")) {
                        crit.add(Restrictions.gt(columnName,
                                                 value.substring(1, value.length())));
                        //fieldClause += "("+columnName +" > '"+value.substring(1,value.length()) + "')";
                    } else if (value.substring(0, 1).equals("<")) {
                        crit.add(Restrictions.le(columnName,
                                                 value.substring(1, value.length())));
                        //fieldClause += "("+columnName +" < '"+value.substring(1,value.length()) + "')";
                    } else if (value.indexOf("%") >= 0) {

                        crit.add(Restrictions.ilike(columnName, value));
                    } else {
                        crit.add(Restrictions.eq(columnName, value));
                    }
                }
            }
            traceLogger.info("Search Result HashMap 2 ==>" + params);
            // Get Order By Clause

            searchresult = crit.list();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {

                try {
                    session.flush();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                session.close();

            } catch (JDBCException e) {
                e.printStackTrace();
            }

        } //Finally
        return searchresult;
    } //End of search


_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Thu Dec 02, 2010 7:28 am 
Beginner
Beginner

Joined: Fri Nov 26, 2010 8:25 am
Posts: 21
Hi Chirag,

As an experiment, could you comment out the
Code:
crit.list();
line, but leave everything else including Session.flush() and tell me whether you still get the exception.

thanks,
Kate.


Top
 Profile  
 
 Post subject: Re: Duplicate identifier in table
PostPosted: Thu Dec 02, 2010 7:46 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
Ok i will try that.

Thanks,
Chirag

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.