1

when i try to get a list of objects i get following exception:

  Hibernate: select this_.newsId as newsId2_0_, this_.newsBrief as newsBrief2_0_, this_.newsContent as newsCont3_2_0_, this_.newsDate as newsDate2_0_, this_.newsTitle as newsTitle2_0_, this_.selected as selected2_0_ from NEWS this_
    Nov 15, 2013 11:04:58 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [action] in context with path [/strts-spring-hbnt-nomaven] threw exception [org.hibernate.exception.SQLGrammarException: could not execute query] with root cause
    java.sql.SQLSyntaxErrorException: ORA-00904: "THIS_"."SELECTED": invalid identifier

ddl

--------------------------------------------------------
--  DDL for Table NEWS
--------------------------------------------------------

  CREATE TABLE "SYSTEM"."NEWS" 
   (    "NEWSID" NUMBER, 
    "NEWSTITLE" VARCHAR2(100 BYTE), 
    "NEWSBRIEF" VARCHAR2(500 BYTE), 
    "NEWSCONTENT" VARCHAR2(2048 BYTE), 
    "NEWSDATE" DATE
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "SYSTEM" ;

--------------------------------------------------------
--  DDL for Index NEWS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "SYSTEM"."NEWS_PK" ON "SYSTEM"."NEWS" ("NEWSID") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "SYSTEM" ;
--------------------------------------------------------
--  Constraints for Table NEWS
--------------------------------------------------------

  ALTER TABLE "SYSTEM"."NEWS" ADD CONSTRAINT "NEWS_PK" PRIMARY KEY ("NEWSID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "SYSTEM"  ENABLE;
  ALTER TABLE "SYSTEM"."NEWS" MODIFY ("NEWSDATE" NOT NULL ENABLE);
  ALTER TABLE "SYSTEM"."NEWS" MODIFY ("NEWSCONTENT" NOT NULL ENABLE);
  ALTER TABLE "SYSTEM"."NEWS" MODIFY ("NEWSBRIEF" NOT NULL ENABLE);
  ALTER TABLE "SYSTEM"."NEWS" MODIFY ("NEWSTITLE" NOT NULL ENABLE);
  ALTER TABLE "SYSTEM"."NEWS" MODIFY ("NEWSID" NOT NULL ENABLE);

news class:

@Entity
@Table(name="NEWS")
public class News {

    private boolean selected=false;
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "news_seq_gen")
    @SequenceGenerator(name = "news_seq_gen", sequenceName = "news_seq")
    private int newsId;

    @Column(name="newsTitle", nullable = false, length = 100)
    private String newsTitle;
    @Column(name="newsDate", nullable = false)
    private Date newsDate;
    @Column(name="newsBrief", nullable = false, length = 500)
    private String newsBrief;
    @Column(name="newsContent", nullable = false, length = 2048)
    private String newsContent;
        //getters and setters 
}

the query :

return sessionFactory.getCurrentSession().createQuery("from News as News").list();

why does hibernate add number to the column names? and where is the problem? any suggestions would be appreciatated.

1 Answer 1

3

You're using Field Access Mode by placing @Id on a class property. This causes hibernate to think of all your fields as table columns. As I understand your DDL, News.selected is a transient property.

Try placing the @Transient annotation on selected.

Sign up to request clarification or add additional context in comments.

1 Comment

yep, it helped :D thnx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.