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.