Hey
i have two entiies connected through a many to one realtionship.
many[category]---------one[game]
columns
idgame----------------------gameid
category------------------game name
I need to have many occureneces of the game primaary key in the category part of the realtionship. I have tried to do this in a session but i get the error. "a different object with the same identifier value was already associated with the session: [org.POJO.Category#1]".
I think my config file is wrong but i maybe wrong. heres my code.
try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
//Create new instance of Contact and set
Transaction tx = session.beginTransaction();
Game gam = new Game();
gam.setgenre(game.getString("genre"));
gam.setgname(game.getString("game_name"));
gam.setplatform(game.getString("platform"));
gam.setdescription(game.getString("description"));
session.saveOrUpdate(gam);
session.update(gam);
JSONObject cate = game.getJSONObject("Category");
int gid = gam.getgameid();
Category cat1 = new Category();
cat1.setgameid(gid);
cat1.setcategory(cate.getString("Category1"));
session.save(cat1);
Category cat2 = new Category();
cat2.setgameid(gid);
cat2.setcategory(cate.getString("Category2"));
session.save(cat2);
My config file for category. its xml.
-hibernate-mapping-
-class name="org.POJO.Category" table="Category"-
-id name="gameid" column="Game_idGame" -
-/id-
-property name="category" column="category"/-
-/class- -/hibernate-mapping-
sdfdsfsdfsdf