I am using Spring MVC + Hibernate
@Resource(name = \"sessionFactory\")
private SessionFactory sessionFactory;
// save
public int
//assumption: this method is adding a player into database and returns generated player id
//Here player is object of class Player
public int addPlayer(Player player){
int player_id; //variable to store generated ID
Session session = sessionFactory.openSession();
session.beginTransaction();
session.persist(player); //adding player
player_id=player.getplayer_id(); //getplayer_id is the getter method for the variable player_id
session. getTransaction().commit();
session.close();
return player_id;
}