If you ever want to insert or update this table, you must have a primary key.
If you just want to select, you can get around it by using a native SQL portion in your code. For example:
Code:
String sql = "";
sql += " select name as Name from phonelist where username = '" + username.trim() + "' ";
SQLQuery query = session.createSQLQuery(sql);
query.addScalar("Name", Hibernate.STRING);
List list = query.list();
String user = "";
for (int i = 0; i < list.size(); i++) {
user = (String) list.get(i);
}
If you select multiple fields, it returns a List<Object[]>, eg.2:
Code:
sql += " select handset as handset, hcode as hcode, ddesc as hcodeDesc,";
sql += " hdate as hdate, hval as description";
sql += " from hshistory , histdesc";
sql += " where handset = '" + handsetNo + "' and hcode = dcode";
sql += " order by hdate DESC";
query = session.createSQLQuery(sql);
query.addScalar("handset", Hibernate.STRING);
query.addScalar("hcode", Hibernate.STRING);
query.addScalar("hcodeDesc", Hibernate.STRING);
query.addScalar("hdate", Hibernate.DATE);
query.addScalar("description", Hibernate.STRING);
List res = query.list();
for (int i = 0; i < res.size(); i++)
{
Object[] objects = (Object[]) res.get(i);
HandsetHistoryVO hHistory = new HandsetHistoryVO();
hHistory.setHandsetNo((String) objects[0]);
hHistory.setHcode((String) objects[1] + " " + (String) objects[2]);
hHistory.setHdate((Date) objects[3]);
hHistory.setDescription((String) objects[4]);
list.add(hHistory);
}
Please note: Hibernate is CRAP at casting correctly, that's why I'm adding all those scalars.
You could, in theory, construct insert and update statements via createSQLQuery as well.
HTH