Results 1 to 6 of 6
  1. #1
    Join Date
    May 2009
    Posts
    3

    Unanswered: insert problem (struts2+hibernate+postgre)

    hi,
    i have a problem with inserting a row to the table. I'm using struts2 + hibernate + postgre. The problem is that, i have a table which have 8 columns and when i try to insert a new row to the table, i get the following error.

    Code:
    Hibernate: 
        select
            nextval ('kisi_pk_seq')
    Hibernate: 
        insert 
        into
            kisi
            (ad, adres, cep_no, dogum_tarihi, mail, soyad, tel_no, DTYPE, id) 
        values
            (?, ?, ?, ?, ?, ?, ?, 'Kisi', ?)
    24.May.2009 02:34:32 org.hibernate.util.JDBCExceptionReporter logExceptions
    WARNING: SQL Error: 0, SQLState: null
    24.May.2009 02:34:32 org.hibernate.util.JDBCExceptionReporter logExceptions
    SEVERE: Tpilı iş girişi 0 insert into kisi (ad, adres, cep_no, dogum_tarihi, mail, soyad, tel_no, DTYPE, id) values (mahmut, malatya, 5347699129, 3886-08-01 +03:00:00, gokhantanisik@hotmail.com, tuncer, 5347699129, 'Kisi', 450) durduruldu.  Nedenini görmek için getNextException fonksiyonu çağırın.
    24.May.2009 02:34:32 org.hibernate.util.JDBCExceptionReporter logExceptions
    WARNING: SQL Error: 0, SQLState: 42703
    24.May.2009 02:34:32 org.hibernate.util.JDBCExceptionReporter logExceptions
    SEVERE: ERROR: column "dtype" of relation "kisi" does not exist
    24.May.2009 02:34:32 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
    SEVERE: Could not synchronize database state with session
    org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    	at com.AKS.util.HibernateUtil.save(HibernateUtil.java:56)
    	at com.AKS.veriTabani.KisiVeriTabani.kisiEkle(KisiVeriTabani.java:16)
    	at com.AKS.veriTabani.deneme.main(deneme.java:12)
    Caused by: java.sql.BatchUpdateException: Tpilı iş girişi 0 insert into kisi (ad, adres, cep_no, dogum_tarihi, mail, soyad, tel_no, DTYPE, id) values (mahmut, malatya, 5347699129, 3886-08-01 +03:00:00, gokhantanisik@hotmail.com, tuncer, 5347699129, 'Kisi', 450) durduruldu.  Nedenini görmek için getNextException fonksiyonu çağırın.
    	at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2528)
    	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1344)
    	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:344)
    	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2663)
    	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
    	... 10 more
    org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
    The problem is the table doesn't have a column with type DTYPE. And i guess i am getting the error because of it. Just to be sure i have tried to insert to an another table and there wasn't any column with type DTYPE and neither an error. Here is the result of that query:

    Code:
    Hibernate: 
        insert 
        into
            sehir
            (ad, kod) 
        values
            (?, ?)
    So, what can be the problem?
    thanks in advance..

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    You said the table has 8 columns? Because you're trying to insert 9 columns into it...
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Hibernate assumes there is a column named DTYPE, so I would assume that this is a hibernate configuration problem.
    Somewhere you told it that the table kisi contains a column named dtype.

  4. #4
    Join Date
    May 2009
    Posts
    3
    Quote Originally Posted by shammat
    Hibernate assumes there is a column named DTYPE, so I would assume that this is a hibernate configuration problem.
    Somewhere you told it that the table kisi contains a column named dtype.
    This is the mapping class for the table. As you can see in the class, there is only 8 column mapped. How can i try to add 9 column?
    Code:
    @Entity
    @Table(name = "kisi")
    public class Kisi implements Serializable {
    	private static final long serialVersionUID = 1L;
    
    	@Id
    	@SequenceGenerator(name = "kisiSeq", sequenceName = "kisi_pk_seq")
    	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "kisiSeq")
    	@Column(name = "id", nullable = false, unique = true)
    	protected int id;
    
    	@Column(name = "ad", nullable = false)
    	protected String ad;
    
    	@Column(name = "soyad", nullable = false)
    	protected String soyad;
    	
    	@Column(name = "dogum_tarihi", nullable = false)
    	protected Date dogumTarihi;
    
    	@Column(name = "adres", nullable = false)
    	protected String adres;
    
    	@Column(name = "tel_no", nullable = false)
    	protected String telNo;
    	
    	@Column(name = "cep_no", nullable = true)
    	protected String cepNo;
    
    	@Column(name = "mail", nullable = false)
    	protected String mail;
    
    	public Kisi(String ad, String soyad, Date dogumTarihi, String adres,
    			String telNo, String cepNo, String mail) {
    		super();
    		this.ad = ad;
    		this.soyad = soyad;
    		this.dogumTarihi = dogumTarihi;
    		this.adres = adres;
    		this.telNo = telNo;
    		this.cepNo = cepNo;
    		this.mail = mail;
    	}
    	
    	public Kisi() {
    
    	}
    
    	public String getAd() {
    		return ad;
    	}
    
    	public void setAd(String ad) {
    		this.ad = ad;
    	}
    
    	public String getSoyad() {
    		return soyad;
    	}
    
    	public void setSoyad(String soyad) {
    		this.soyad = soyad;
    	}
    
    	public Date getDogumTarihi() {
    		return dogumTarihi;
    	}
    
    	public void setDogumTarihi(Date dogumTarihi) {
    		this.dogumTarihi = dogumTarihi;
    	}
    
    	public String getAdres() {
    		return adres;
    	}
    
    	public void setAdres(String adres) {
    		this.adres = adres;
    	}
    
    	public String getTelNo() {
    		return telNo;
    	}
    
    	public void setTelNo(String telNo) {
    		this.telNo = telNo;
    	}
    
    	public String getCepNo() {
    		return cepNo;
    	}
    
    	public void setCepNo(String cepNo) {
    		this.cepNo = cepNo;
    	}
    
    	public String getMail() {
    		return mail;
    	}
    
    	public void setMail(String mail) {
    		this.mail = mail;
    	}
    
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    
    }
    This is the code part that i try to insert the row. So where is the 9th one?

    Code:
    Kisi k= new Kisi("name","surname",new Date(1986,7,1),"malatya",
    		"5347699133","5347699133","g@hotmail.com");
    MyDatabase.insertKisi(k);
    Also the configuration part for the class is. As i said in the first post, i can run an insert query with an another table. And everything seems the same with this one
    Code:
    <mapping class="com.AKS.beans.Kisi" />
    Last edited by seleciii44; 05-24-09 at 05:50.

  5. #5
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by seleciii44
    This is the mapping class for the table. As you can see in the class, there is only 8 column mapped.
    I have no experience with Hibernate.
    You should take this question to a Java or Hibernate forum.
    It definitely is not a problem with Postgres

  6. #6
    Join Date
    May 2009
    Posts
    3
    i found out the problem. I was using inheritance and i didn't know that i needed to specify the descriminator column.
    thanks anyway..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •