java - Self OneToMany relation with jointable uknown column error -


i have these basenews , news entity:

@mappedsuperclass public class basenews extends model {     public static model.finder<long, news> find = new model.finder<long, news>(news.class);      public static news getnewsbyid(long newsid) {         return find.byid(newsid);     }      public static list<news> getnewslist(int pageindex, int pagesize) {         return find.where()                    .findpagedlist(pageindex, pagesize)                    .getlist();     }  }       @entity     @table(name = "news")     public class news extends basenews implements serializable {          @id         @generatedvalue(strategy = generationtype.identity)         private long id;   //    @manytoone //    private news basenews;           @onetomany(cascade = cascadetype.all)//,mappedby = "basenews")         @jointable(name = "news_similar",                    joincolumns = {@joincolumn(name = "base_news_id")},                    inversejoincolumns = {@joincolumn(name = "similar_news_id")}         )         private list<news> similarnews;         //getters, setters...     } 

in both uni , bidirectional case

select t0.id c0, t0.base_news_id c1 news t0 

gives error unknown column base_news_id

am doing wrong way?

should create new entity newssimilar instead of using jointable?

actually reversing existing table.

create table news_similar (     id int auto_increment primary key,     base_news_id int not null,     similar_news_id int not null,     constraint news_similar_ibfk_1  foreign key (base_news_id) references news (id) on update cascade on delete cascade,     constraint news_similar_ibfk_2  foreign key (similar_news_id) references news (id) on update cascade on delete cascade ) 

edit: news_id unrelated problem other field, anyway solved it.

it turns out have manytomany relation so, solution this

@entity @table(name = "news") public class news extends basenews implements serializable {      @id     @generatedvalue(strategy = generationtype.identity)     private long id;       @manytomany(cascade = cascadetype.all)     @jointable(name = "news_similar",                joincolumns = {@joincolumn(name = "base_news_id")},                inversejoincolumns = {@joincolumn(name = "similar_news_id")}     )     private list<news> similarnews;     //getters, setters... } 

came solution while reading article:

https://www.thoughts-on-java.org/ultimate-guide-association-mappings-jpa-hibernate/


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -