java - Hibernate Query for unmapped join table -
i'm j2ee newbie trying learn hibernate. have 2 tables, system , game, , join table called systems_game.
i want able put in game_id , of systems game.
i using annotations on system.java , game.java create many-to-many relationship.
@manytomany(targetentity = system.class, cascade = { cascadetype.all }) @jointable(name="systems_game", joincolumns = { @joincolumn(name="game_id") }, inversejoincolumns = { @joincolumn(name="system_id") }) private list<game> games;
and here method using try result want.
@override public list getgamesystem(){ return sessionfactory.getcurrentsession().createquery("from systems_game s s.game_id=1").list(); }
when runs, get
"request processing failed; nested exception org.hibernate.hql.ast.querysyntaxexception: systems_game not mapped [from systems_game s s.game_id=1]"
i know don't have systems_game mapped in hibernate.cfg.xml file, don't know how map since don't have class it. need many-to-many relationship different way , give it's own class? other way overlooking me achieve desired result?
if need more code post.
2 ways this:
sql way:
sessionfactory.getcurrentsession().createnativequery("select * systems_game s s.game_id=1")...
hibernate(java) way:
game = session.createquery(from game id = 1).uniqueresult() list systems = game.getsystems()
just try pseudocode!
Comments
Post a Comment