hibernate & spring, invalid identifier -


i have stuck on dealing db using hibernate orm in spring mvc environment.

i have tables; i'm not gonna tell tables(if want, edit post)

the problem when hibernate runs, generates sql - can see sql configuring "hbm2_ddl auto" - sql has invalid identifier.

select newsreplie0_.news_article# news6_3_4_, newsreplie0_.reply# reply1_4_,  newsreplie0_.reply# reply1_4_3_, newsreplie0_.account_account# account5_4_3_,  newsreplie0_.content content4_3_, newsreplie0_.dt dt4_3_,  newsreplie0_.news_article# news6_4_3_, newsreplie0_.reply_at reply4_4_3_,  account1_.account# account1_0_0_, account1_.email email0_0_,  account1_.passwd passwd0_0_, accountpro2_.account# account1_1_1_,  accountpro2_.nickname nickname1_1_, accountsec3_.account# account1_2_2_,  accountsec3_.activate_key activate2_2_2_, accountsec3_.activated activated2_2_,  accountsec3_.enabled enabled2_2_, accountsec3_.login_failed login5_2_2_  news_reply newsreplie0_  left outer join  cookingstep.account account1_ on newsreplie0_.account_account#=account1_.account#  left outer join  cookingstep.account_profile accountpro2_ on account1_.account#=accountpro2_.account#  left outer join  cookingstep.account_security accountsec3_ on account1_.account#=accountsec3_.account#  newsreplie0_.news_article#=9  {failed after 4 msec} 

the above statement sql generated hibernate. , error is:

java.sql.sqlsyntaxerrorexception:  ora-00904: "newsreplie0_"."account_account#": invalid identifier 

in exception message, there column called "account_account#". should "account#", not following "account_".

so, how remove word ?

edit:

thank reply. have asked similar question before. , checked out article, seems problem @joincolumn annotation missing. works out.

here entities.

account.java user information

package com.musicovery12.cookingstep.persistence.model;  import java.io.serializable; import java.util.hashset; import java.util.set;  import javax.persistence.cascadetype; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.fetchtype; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.onetomany; import javax.persistence.onetoone; import javax.persistence.sequencegenerator; import javax.persistence.table; import javax.persistence.uniqueconstraint;   @entity @table(name="account", catalog="cookingstep", uniqueconstraints= {         @uniqueconstraint(columnnames="email") }) public class account implements serializable{      private static final long serialversionuid = 1l;      private int accountid;     private string email;     private string password;     private set<userrole> userroles = new hashset<userrole>(0);     private accountprofile profile;     private accountsecurity security;     private set<news> newslist;     private set<newsreply> newsreplylist;      public account() {}      @id     @generatedvalue(strategy=generationtype.sequence, generator="seq_account")     @sequencegenerator(name="seq_account", sequencename="seq_account", allocationsize=1)     @column(name="account#", unique=true, nullable=false)     public int getaccountid() {         return accountid;     }      public void setaccountid(int accountid) {         this.accountid = accountid;     }      @column(name="email", unique=true, nullable=false)     public string getemail() {         return email;     }      public void setemail(string email) {         this.email = email;     }      @column(name="passwd", nullable=false)     public string getpassword() {         return password;     }      public void setpassword(string password) {         this.password = password;     }      @onetomany(mappedby="pk.account", fetch=fetchtype.eager, cascade=cascadetype.all)     public set<userrole> getuserroles() {         return userroles;     }      public void setuserroles(set<userrole> userroles) {         this.userroles = userroles;     }      @onetoone(mappedby="account", fetch=fetchtype.eager, cascade=cascadetype.all)     public accountprofile getprofile() {         return profile;     }      public void setprofile(accountprofile profile) {         this.profile = profile;     }      @onetoone(mappedby="account", fetch=fetchtype.eager, cascade=cascadetype.all)     public accountsecurity getsecurity() {         return security;     }      public void setsecurity(accountsecurity security) {         this.security = security;     }      @onetomany(mappedby="account", fetch=fetchtype.lazy, cascade=cascadetype.all)     public set<news> getnewslist() {         return newslist;     }      public void setnewslist(set<news> newslist) {         this.newslist = newslist;     }      @onetomany(mappedby="account", fetch=fetchtype.lazy, cascade=cascadetype.all)     public set<newsreply> getnewsreplylist() {         return newsreplylist;     }      public void setnewsreplylist(set<newsreply> newsreplylist) {         this.newsreplylist = newsreplylist;     }     } 

and newsreply.java news community article's reply list.

package com.musicovery12.cookingstep.persistence.model;  import java.util.date;  import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.manytoone; import javax.persistence.sequencegenerator; import javax.persistence.table; import javax.persistence.temporal; import javax.persistence.temporaltype;  @entity @table(name="news_reply") public class newsreply {      private int replyid;     private news news;     private date date;     private string content;     private account account;     private int replyat;       @id     @generatedvalue(strategy=generationtype.sequence, generator="gen_seq")     @sequencegenerator(name="gen_seq", sequencename="gen_seq", allocationsize=1)     @column(name="reply#", unique=true, nullable=false)     public int getreplyid() {         return replyid;     }     public void setreplyid(int replyid) {         this.replyid = replyid;     }      @temporal(temporaltype.date)     @column(name="dt")     public date getdate() {         return date;     }     public void setdate(date date) {         this.date = date;     }      @column(name="content", nullable=false)     public string getcontent() {         return content;     }     public void setcontent(string content) {         this.content = content;     }      @column(name="reply_at")     public int getreplyat() {         return replyat;     }     public void setreplyat(int replyat) {         this.replyat = replyat;     }      @manytoone     public news getnews() {         return news;     }     public void setnews(news news) {         this.news = news;     }      @manytoone     @joincolumn(name="account#", referencedcolumnname="account#")     public account getaccount() {         return account;     }     public void setaccount(account account) {         this.account = account;     } } 

in newsreply.java, there no joincolumn annotation point foreing key column name.

thank you.

@manytoone @joincolumn(name="account#", referencedcolumnname="account#") public account getaccount() {     return account; } 

this problem, tell hibernate table has technical name of account# not allowed.

what can force hibernate use # defining

@manytoone @joincolumn(name="`account#`", referencedcolumnname="`account#`") public account getaccount() {     return account; } 

but bad style , have on owning-side too.


why dont let hibernate create entitys you? more precisly!


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -