Hibernate version:2.1.3
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:MySQL
Debug level Hibernate log excerpt:
Hi,everyone!
I use JBX + Hibernate to write a query method, and show the result in a JTable. Here is my code:
Code:
String rowData[][] = new String[255][5];
UserInfo users[] = null;
public void query(){
try {
Configuration conf = new Configuration().addClass(UserInfo.class);
sessionFactory = conf.buildSessionFactory();
s = sessionFactory.openSession();
Transaction t = s.beginTransaction();
}
catch (MappingException ex) {
ex.printStackTrace();
}
catch (HibernateException ex) {
ex.printStackTrace();
}
if (tfName.getText() == "all"){
try {
tx = s.beginTransaction();
list = s.find("from UserInfo as ui");
tx.commit();
s.flush();
s.close();
}
catch (HibernateException ex1) {
System.out.println("excute sql1 query failed.");
ex1.printStackTrace();
}
}else{
try {
list = s.find("from UserInfo as ui where ui.name = ?" , tfName.getText() , Hibernate.STRING);
s.flush();
s.close();
}
catch (HibernateException ex2) {
System.out.println("excute sql2 query failed.");
ex2.printStackTrace();
}
}
for(int i=0 ; i<list.size() ; i++){
try{
if(list == null){
System.out.println("list equals NULL!");
}
System.out.println(list.size());
System.out.println(i);
users[i] = (UserInfo)list.get(i);
}catch(java.lang.NullPointerException ex){
System.out.println("equals null!");
}
rowData[i][0] = users[i].getId();
rowData[i][1] = users[i].getName();
rowData[i][2] = users[i].getModuleNo();
rowData[i][3] = users[i].getMobileNo();
rowData[i][4] = users[i].getAccount();
}
JTable jTable1 = new JTable(rowData,columnName);
jTable1.setBounds(new Rectangle(14, 109, 338, 109));
jTable1.setEnabled(false);
jTable1.setFont(new java.awt.Font("Dialog", 0, 12));
panel1.add(jTable1, null);
}
But when running, it always be a NullpointerException. I know I havn't initalize the rowData[][] and users[], but I don't know how to make in works.
Any ideas?