-->
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.  [ 4 posts ] 
Author Message
 Post subject: duplicate column problem on insert
PostPosted: Wed Jan 05, 2005 8:06 am 
Newbie

Joined: Thu Dec 23, 2004 2:28 pm
Posts: 4
Hi, I have a struts app that I am converting to hibernate 2.1 and am seeing the id property of my class appear twice in queries - no problem on select but causes inserts to fail. Here is what I see in stdout.log, and you can see the id property prn_id appear twice, once in lowercase once upper:

Code:
Hibernate: select lacrecord0_.PRN_ID as PRN_ID, lacrecord0_.prn_id as prn_id, lacrecord0_.care_start_date as care_sta3_, lacrecord0_.pupil_id as pupil_id, lacrecord0_.soscis_no as soscis_no, lacrecord0_.upn as upn, lacrecord0_.forename as forename, lacrecord0_.surname as surname, lacrecord0_.dob as dob, lacrecord0_.sex as sex, lacrecord0_.ethnic_code as ethnic_11_, lacrecord0_.mfl as mfl, lacrecord0_.lac_end_date as lac_end13_, lacrecord0_.notes as notes from CLIENT_NOTES lacrecord0_ where (lacrecord0_.PRN_ID='P10995' )
results: 1
Hibernate: insert into CLIENT_NOTES (prn_id, care_start_date, pupil_id, soscis_no, upn, forename, surname, dob, sex, ethnic_code, mfl, lac_end_date, notes, PRN_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
WARN  - SQL Error: 957, SQLState: 42000
ERROR - ORA-00957: duplicate column name

WARN  - SQL Error: 957, SQLState: 42000
ERROR - ORA-00957: duplicate column name

WARN  - SQL Error: 957, SQLState: 42000
ERROR - ORA-00957: duplicate column name

WARN  - SQL Error: 957, SQLState: 42000
ERROR - ORA-00957: duplicate column name

ERROR - Could not synchronize database state with session


Mapping documents:
Code:
<hibernate-mapping>

        <class name="uk.gov.brightonhove.lac.dao.LacRecord" table="CLIENT_NOTES">
               
            <id name="prn_id" type="string" unsaved-value="null">
                <column name="PRN_ID" sql-type="char(32)" not-null="true" />
                <generator class="uuid.hex"/>
            </id>
            <property name="care_start_date" />
            <property name="pupil_id" />
            <property name="soscis_no" />
            <property name="upn" />
            <property name="forename" />
            <property name="surname" />
            <property name="dob" />
            <property name="sex" />
            <property name="ethnic_code" />
            <property name="mfl" />
            <property name="lac_end_date" />
            <property name="notes" />
   
   
        </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
public void updateRecord(LacRecord record) {
        try {
            Session session = HibernateUtil.currentSession();
            Transaction tx = session.beginTransaction();
            session.save(record);
            tx.commit();

            HibernateUtil.closeSession();
        } catch (HibernateException he) {
            System.out.println("updateRecord: "+he);
        }
                       
    }


the source for LacRecord:
Code:
public class LacRecord {
   
    private String prn_id;
    private Date care_start_date;
    private Integer pupil_id;
    private Integer soscis_no;
    private String upn;
    private String forename;
    private String surname;
    private Date dob;
    private Character sex;
    private String ethnic_code;
    private Integer mfl;
    private Date lac_end_date;
    private String notes;
   
   
    public LacRecord() {
       
    }
   
    public String getPrn_id() {
        return prn_id;
    }
   
    private void setPrn_id(String prn_id) {
        this.prn_id = prn_id;
    }
   
    public Date getCare_start_date() {
        return care_start_date;
    }

    public void setCare_start_date(Date care_start_date) {
        this.care_start_date = care_start_date;
    }

    public Integer getPupil_id() {
        return pupil_id;
    }

    public void setPupil_id(Integer pupil_id) {
        this.pupil_id = (pupil_id == null) ? new Integer(0) : pupil_id;
    }
   
    public Integer getSoscis_no() {
        return soscis_no;
    }
   
    public void setSoscis_no(Integer soscis_no) {
        this.soscis_no = (soscis_no == null) ? new Integer(0) : soscis_no;;
    }
   
    public String getUpn() {
        return upn;
    }
   
    public void setUpn(String upn) {
        this.upn = upn;
    }
   
    public String getForename() {
        return forename;
    }

    public void setForename(String forename) {
        this.forename = forename;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public Date getDob() {
        return dob;
    }

    public void setDob(Date dob) {
        this.dob = dob;
    }

    public Character getSex() {
        return sex;
    }

    public void setSex(Character sex) {
        this.sex = (sex == null) ? new Character(' ') : sex;
    }

    public String getEthnic_code() {
        return ethnic_code;
    }

    public void setEthnic_code(String ethnic_code) {
        this.ethnic_code = ethnic_code;
    }

    public Integer getMfl() {
        return mfl;
    }

    public void setMfl(Integer mfl) {
        this.mfl = (mfl == null) ? new Integer(0) : mfl;
    }

    public Date getLac_end_date() {
        return lac_end_date;
    }

    public void setLac_end_date(Date lac_end_date) {
        this.lac_end_date = lac_end_date;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }
   
    public String getCare_start_dateAsString() {
        return getDateAsString(care_start_date);
    }
   
    public String getLac_end_dateAsString() {
        return getDateAsString(lac_end_date);
    }
   
    public void setLac_end_date(String lac_end_date) {
       
        //if this date is in the format yyyy-mm-dd DateFormat can't parse it
        if(lac_end_date.trim().matches("^\\d{4}-\\d{2}-\\d{2}")) {
            Calendar c = Calendar.getInstance();
            c.set(Calendar.YEAR, Integer.valueOf(lac_end_date.substring(0,4)).intValue());
            c.set(Calendar.MONTH, (Integer.valueOf(lac_end_date.substring(5,7)).intValue()-1));
            c.set(Calendar.DATE, Integer.valueOf(lac_end_date.substring(8,10)).intValue());
            this.dob = c.getTime();
        } else if(!lac_end_date.equals("")){
            DateFormat df = DateFormat.getDateInstance();
            try {
                this.dob = df.parse(lac_end_date);
            } catch (ParseException pe) {
                System.out.println(pe);
            }
        }
       
    }
   
    public void setDob(String dob) {
       
        //if this date is in the format yyyy-mm-dd DateFormat can't parse it
        if(dob.trim().matches("^\\d{4}-\\d{2}-\\d{2}")) {
            Calendar c = Calendar.getInstance();
            c.set(Calendar.YEAR, Integer.valueOf(dob.substring(0,4)).intValue());
            c.set(Calendar.MONTH, (Integer.valueOf(dob.substring(5,7)).intValue()-1));
            c.set(Calendar.DATE, Integer.valueOf(dob.substring(8,10)).intValue());
            this.dob = c.getTime();
        } else if(!dob.equals("")){
            DateFormat df = DateFormat.getDateInstance();
            try {
                this.dob = df.parse(dob);
            } catch (ParseException pe) {
                System.out.println(pe);
            }
        }
    }
   
    public void setCare_start_date(String care_start_date) {
        //if this date is in the format yyyy-mm-dd DateFormat can't parse it
        if(care_start_date.trim().matches("^\\d{4}-\\d{2}-\\d{2}")) {
            Calendar c = Calendar.getInstance();
            c.set(Calendar.YEAR, Integer.valueOf(care_start_date.substring(0,4)).intValue());
            c.set(Calendar.MONTH, (Integer.valueOf(care_start_date.substring(5,7)).intValue()-1));
            c.set(Calendar.DATE, Integer.valueOf(care_start_date.substring(8,10)).intValue());
            this.care_start_date = c.getTime();
        } else if(!care_start_date.equals("")){
            DateFormat df = DateFormat.getDateInstance();
            try {
                this.care_start_date = df.parse(care_start_date);
            } catch (ParseException pe) {
                System.out.println(pe);
            }
        }
    }
   
    public String getDobAsString() {
        return getDateAsString(dob);
    }
   
    private String getDateAsString(Date d) {
        if (d == null) {
            return "";
        } else {
             Calendar c = Calendar.getInstance();
             c.setTime(d);
             return c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH)+1) + "-" + c.get(Calendar.DATE);
        }
    }
   
}


Any ideas? TIA


Top
 Profile  
 
 Post subject: remove column...
PostPosted: Wed Jan 05, 2005 5:13 pm 
Newbie

Joined: Thu Apr 22, 2004 3:21 pm
Posts: 15
I usually do the id this way:

<id name="prn_id" type="string" unsaved-value="null" column="PRN_ID">
<generator class="uuid.hex"/>
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 5:21 pm 
Newbie

Joined: Thu Dec 23, 2004 2:28 pm
Posts: 4
thanks, I'll try that.....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 2:17 pm 
Newbie

Joined: Mon Feb 14, 2005 12:14 am
Posts: 14
Location: Boston, USA
What is the solution for this? I am facing the same problem.
Please reply.
Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

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.