-->
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.  [ 3 posts ] 
Author Message
 Post subject: org.hibernate.exception.SQLGrammarException: could not execu
PostPosted: Thu Aug 26, 2010 8:05 am 
Newbie

Joined: Thu Mar 19, 2009 4:47 am
Posts: 8
Hi All,

I am getting Exception as:
org.hibernate.exception.SQLGrammarException: could not execute query

The reason is:
SEVERE: ORA-00904: "THIS_"."COMPANYTYPE_COMPANY_TYPE_ID": invalid identifier

My table structure is:
Code:
Code:
CREATE TABLE TBCOMPANY
(
  COMPANYID         NUMBER(10)                  NOT NULL,
  COMPANY_ADDRESS   VARCHAR2(255 CHAR),
  COMPANY_DESC      VARCHAR2(255 CHAR),
  COMPANY_NAME      VARCHAR2(255 CHAR),
  COMPANY_TYPE_ID   NUMBER(10),
  COMPANY_VERTICAL  VARCHAR2(255 CHAR)
)ALTER TABLE TBCOMPANY ADD (
  PRIMARY KEY
(COMPANYID)
Code:
CREATE TABLE TBCOMPANYTYPE
(
  COMPANY_TYPE_ID    NUMBER(10)                 NOT NULL,
  COMPANY_TYPE_DESC  VARCHAR2(255 CHAR)
)ALTER TABLE TBCOMPANYTYPE ADD (
  PRIMARY KEY
(COMPANY_TYPE_ID)

My Java code is:
Code:
Code:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "TBCOMPANYTYPE")
public class TBCompanyType {
   
   public Integer company_id;
   public String company_type_desc;

   public TBCompanyType(){}
   
   public TBCompanyType(String companyTypeDesc) {
      
      this.company_type_desc = companyTypeDesc;
   }
   
   @Id
   @GeneratedValue
   @Column(name = "COMPANY_TYPE_ID")
   public Integer getCompany_type_id() {
      return company_id;
   }

   public void setCompany_type_id(Integer company_id) {
      this.company_id = company_id;
   }
   
   @Column(name = "COMPANY_TYPE_DESC")
   public String getCompany_type_desc() {
      return company_type_desc;
   }
   
   public void setCompany_type_desc(String companyTypeDesc) {
      company_type_desc = companyTypeDesc;
   }
   
   
   

}

and
Code:
Code:
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;



@Entity
@Table(name = "TBCOMPANY")
public class TBCompany  implements java.io.Serializable{
private Integer companyid;

   
   private String company_name;

   
   private String company_desc;

   
   private String company_vertical;

   
   private String company_address;
   
   /**
    *
    */
   private static final long serialVersionUID = 1L;
   
   public TBCompany(){}

   public TBCompany(String companyName, String companyDesc,
         String companyVertical, String companyAddress, Integer companyTypeId,TBCompanyType companyType) {
      
      
      this.company_name = companyName;
      this.company_desc = companyDesc;
      this.company_vertical = companyVertical;
      this.company_address = companyAddress;
      
      this.companyType = companyType;
   }

   
   
   
   
   
   private com.novire.DO.TBCompanyType companyType;
   
   public void setCompanyid(Integer companyid) {
      this.companyid = companyid;
   }
   
   @Id()
     @Column(name = "COMPANYID")
     @GeneratedValue
   public Integer getCompanyid() {
      return companyid;
   }

   
   @Column(name = "COMPANY_NAME", length = 255)
   public String getCompany_name() {
      return company_name;
   }

   public void setCompany_name(String companyName) {
      company_name = companyName;
   }
   @Column(name = "company_desc", length = 255)
   public String getCompany_desc() {
      return company_desc;
   }

   public void setCompany_desc(String companyDesc) {
      company_desc = companyDesc;
   }
   @Column(name = "company_vertical", length = 255)
   public String getCompany_vertical() {
      return company_vertical;
   }

   public void setCompany_vertical(String companyVertical) {
      company_vertical = companyVertical;
   }
   @Column(name = "company_address", length = 255)
   public String getCompany_address() {
      return company_address;
   }

   public void setCompany_address(String companyAddress) {
      company_address = companyAddress;
   }
   
   public void setCompanyType(com.novire.DO.TBCompanyType companyType) {
      this.companyType = companyType;
   }

   @ManyToOne(cascade = CascadeType.ALL)
   public TBCompanyType getCompanyType() {
      return this.companyType;
   }
   

   

}

The Code that is used to list is:
Code:
Code:
public List<TBCompany> listCompany() {
      List<TBCompany> companies = null;
      try {
         session = HibernateUtil.getSessionFactory().getCurrentSession();
         transaction = session.beginTransaction();
//         companies = session.createQuery("from TBCompany").list();
         DetachedCriteria criteria = DetachedCriteria.forClass(TBCompany.class);
         Criteria criteria1 = criteria.getExecutableCriteria(session);
         companies = criteria1.list();
      } catch (Exception e) {
         e.printStackTrace();
      }
      return companies;
      
   }

The stacktrace is:
Code:
Code:
Hibernate: select this_.COMPANYID as COMPANYID3_1_, this_.companyType_COMPANY_TYPE_ID as companyT6_3_1_, this_.company_address as company2_3_1_, this_.company_desc as company3_3_1_, this_.COMPANY_NAME as COMPANY4_3_1_, this_.company_vertical as company5_3_1_, tbcompanyt2_.COMPANY_TYPE_ID as COMPANY1_2_0_, tbcompanyt2_.COMPANY_TYPE_DESC as COMPANY2_2_0_ from TBCOMPANY this_ left outer join TBCOMPANYTYPE tbcompanyt2_ on this_.companyType_COMPANY_TYPE_ID=tbcompanyt2_.COMPANY_TYPE_ID
Aug 26, 2010 3:39:21 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 904, SQLState: 42000
Aug 26, 2010 3:39:21 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-00904: "THIS_"."COMPANYTYPE_COMPANY_TYPE_ID": invalid identifier

org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
...........................Many lines
Caused by: java.sql.SQLException: ORA-00904: "THIS_"."COMPANYTYPE_COMPANY_TYPE_ID": invalid identifier

   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)

   ... 102 more

I am unable to understand where am i making mistake. There is no column either in database or DO that is:
COMPANYTYPE_COMPANY_TYPE_ID

Please help me out.

Thanks and Regards,
Vikash Anand.


Top
 Profile  
 
 Post subject: Re: org.hibernate.exception.SQLGrammarException: could not execu
PostPosted: Fri Aug 27, 2010 5:20 am 
Newbie

Joined: Fri Aug 20, 2010 7:57 am
Posts: 7
Hi,
As u have shown in the problem
CREATE TABLE TBCOMPANY
(
COMPANYID NUMBER(10) NOT NULL,
COMPANY_ADDRESS VARCHAR2(255 CHAR),
COMPANY_DESC VARCHAR2(255 CHAR),
COMPANY_NAME VARCHAR2(255 CHAR),
COMPANY_TYPE_ID NUMBER(10),
COMPANY_VERTICAL VARCHAR2(255 CHAR)
)ALTER TABLE TBCOMPANY ADD (
PRIMARY KEY
(COMPANYID)


I think you should define a foreign key relationship for COMPANY_TYPE_ID at the database level to create a many to one relation ship.

many to one is not getting the relation thats why this error is occuring.

I hope this may correct your problem :)


Top
 Profile  
 
 Post subject: Re: org.hibernate.exception.SQLGrammarException: could not execu
PostPosted: Fri Aug 27, 2010 5:23 am 
Newbie

Joined: Thu Mar 19, 2009 4:47 am
Posts: 8
Hi,

Thanks for comment.

I solved this by adding:
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "COMPANY_TYPE_ID", unique = false, nullable = false, insertable = true, updatable = true)
public TBCompanyType getCompanyType() {
return this.companyType;
}

i.e. @JoinColumn

and it worked like a charm

Thanks,
Vikash Anand


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.