It's a simple question, but I'm new to Hibernate and working in Hibernate 4.2.7. Here is my scenario.
I have a list of product codes so I'm looping through the values like:
Vector<productslist> p = prodcts.getlists();
int size = p.size();
for (int i = 0; i < size; i++) {
productslist pl = p.elementAt(i)
p.setProductcode(pl.getProductcode());
p.setProductName(pl.getProductName());
session.save(p);
}
Before inserting into database I need to check if the productcode exists in the database. If not I can insert the values, if it exists I need to return back the productID for that productcode.
productID is auto-generated by database.
Please advise how to achieve this.
p.setProductcode(),p.setProductName(). "p" is a Vector in your code, so of course there are no such methods there. 2) Related to yourproductslistclass: class names in Java by convention should be upper camelCase (a.k.a. PascalCase). Read more in Code Conventions for the Java Programming Language