This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a somewhat annoying problem. In my database (MSSQL) I have a "users" table. The convention for hibernate seems to be to name the class as the singular so I have "data.User" as a classname. When I issue a query:
String query = "select user from user " + "in class data.User " + "where username=:name"; and call: List list = sess.find(query, name, Hibernate.STRING);
I get an SQL exception (invalid use of keyword USER).
It works if I change the classname + xml files to use "data.XUser" but should I really have to? Is there some way to tell hibernate about keywords or should I just use a different convention for class naming?
My recommendation is to not use the table name user. modify it to something that is prefixed. USER is a keyword in MSSQL and you have weird things happen if you continue to use it. In select statements within query analyzer you must specify it as ["user"] for example. This is what your hibernate query is attempting to use in the select statement.
Dan, Hibernate was takeing this approach as it is a normal naming convention: the table represents the collection of User tuples. It is quite common to use singular for naming tables/entities. You are not talking about how you obtain the classname + hbm.xml files? Are you using Middlegen? Are you using the Hibernate tool for this?