I know that this will not work, which sucks IMO, but I am wondering what is my best solution. After some searching I have found out about ORM and hibernate. After finding out about them I have found many people who say its more hassle than it is worth and promotes laziness. Please can anyone point me in a good direction?
//Setup the weapon classes
logger.info("Initializing the weapon classes.");
stat = conn.prepareStatement("SELECT *" +
" FROM " + DB_NAME + ".weapons");
rs = stat.executeQuery();
while (rs.next()) {
Weapon rs.getString("name") = new Weapon(rs.getint("weapon_id"), rs.getString("name"), rs.getString("description"), rs.getString("filename"), rs.getint("rarity"), rs.getint("sell_price"), rs.getint("quantity_max"), rs.getint("slot"), rs.getint("level_requirement"), rs.getint("strength_requirement"), rs.getint("dexterity_requirement"), rs.getint("intelligence_requirement"), rs.getint("enchanted_increase"), rs.getint("enchanted_cost"), rs.getint("hit_min"), rs.getint("hit_max"), rs.getint("speed"), rs.getint("elemental_type"), rs.getint("elemental_hit_min"), rs.getint("elemental_hit_max"));
}
I know this has been asked many times, but I am just finding so many contradictory opinions. 🙁
Using an ORM depends on your project size. Personally, and by looking at your understanding of Java, I would not recommend that you jump into hibernate and such for now. I would suggest that you play directly with SQL first so you have a better understanding of persistence.
As for the code you posted, here is what you could do :
Avoid having a constructor (or even a method!) with so many arguments. Unless you are exporting your class to a third party or exposing it to some user plugins and don’t want anyone to change the internal values, don’t worry about setters! Then each
set*methods returnthisso they can be chained. For example :And you can, then access your weapons using the
Map. Like, for example :