1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| Location loc = new Location();
LocationHome locHome = new LocationHome();
loc.setName("Annemasse");
logger.info(anotherLoc.getLocationId()); // Prints NULL
logger.info(anotherLoc.getName()); // Prints "Annemasse"
logger.info(anotherLoc.getLat()); // Prints NULL
loc = locHome.insertUpdate(loc);
// a ce niveau, la base de donnee contient location Annemasse et disant que le
// location_id alloué par mysql est 1
logger.info(logger.infoanotherLoc.getLocationId()); // Prints 1
logger.info(anotherLoc.getName()); // Prints "Annemasse"
logger.info(anotherLoc.getLat()); // Prints NULL
////////////////////////////////////////////////////////////////
// une autre execution dans le meme programme ou meme un autre programme
////////////////////////////////////////////////////////////////
Location anotherLoc = new Location();
anotherLoc.setName("Annemasse");
anotherLoc.setLat("12.02482");
// a ce point la base contient deja une location avec un nom
"Annemasse"
anotherLoc = locHome.insertUpdate(anotherLoc);
// Ici je devrai avoir aucune erreur, il devrai mettre a jour la location avec le meme nom
// mais en executant insertOrUpdate (merge, saveOrUpdate)
// ca remet une erreur a chaque fois disant duplicated entry ..
logger.info(anotherLoc.getLocationId()); // Prints 1
logger.info(anotherLoc.getName()); // Prints "Annemasse"
logger.info(anotherLoc.getLat()); // Prints "12.02482" |
Partager