Need a bit of help here... I have a simple database that I am mapping one table,
USERS, to a class,
Users. In my
Test class, I am simply trying to print a list of each user's name. I can get the count of all users, however whenever I try the following line:
Code:
System.out.println ( user.getName() );
it throws a
NullPointerException error.
Here is my code for the Test class:
Code:
public class Test{
public static void main (String[] args)
{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Criteria crit = session.createCriteria(Users.class);
List result = crit.list();
System.out.println("FOUND: "+result.size());
for (Iterator iter = result.iterator(); iter.hasNext();){
Users user = (Users) iter.next(); //}
System.out.println ("USERNAME: "+user.getName()); }
session.getTransaction().commit();
session.close();
}
}
And here is the contents of my hibernate log file:
Code:
15:32:33,315 INFO Environment:500 - Hibernate 3.2.0.cr5
15:32:33,325 INFO Environment:533 - hibernate.properties not found
15:32:33,325 INFO Environment:667 - Bytecode provider name : cglib
15:32:33,325 INFO Environment:584 - using JDK 1.4 java.sql.Timestamp handling
15:32:33,425 INFO Configuration:1350 - configuring from resource: /hibernate.cfg.xml
15:32:33,425 INFO Configuration:1327 - Configuration resource: /hibernate.cfg.xml
15:32:33,525 INFO Configuration:507 - Reading mappings from resource: com\pac\server\common\oraclevars\OracleVars.hbm.xml
15:32:33,625 INFO HbmBinder:300 - Mapping class: com.pac.server.common.oraclevars.Workstations -> WORKSTATIONS
15:32:33,665 INFO HbmBinder:300 - Mapping class: com.pac.server.common.oraclevars.Users -> USERS
15:32:33,665 INFO Configuration:1465 - Configured SessionFactory: null
15:32:33,745 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
15:32:33,745 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
15:32:33,745 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
15:32:33,836 INFO DriverManagerConnectionProvider:80 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:localdb
15:32:33,836 INFO DriverManagerConnectionProvider:86 - connection properties: {user=mpac_mgr, password=****}
15:32:34,316 INFO SettingsFactory:81 - RDBMS: Oracle, version: Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
15:32:34,326 INFO SettingsFactory:82 - JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0
15:32:34,346 INFO Dialect:141 - Using dialect: org.hibernate.dialect.OracleDialect
15:32:34,356 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
15:32:34,356 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
15:32:34,356 INFO SettingsFactory:134 - Automatic flush during beforeCompletion(): disabled
15:32:34,356 INFO SettingsFactory:138 - Automatic session close at end of transaction: disabled
15:32:34,356 INFO SettingsFactory:145 - JDBC batch size: 15
15:32:34,356 INFO SettingsFactory:148 - JDBC batch updates for versioned data: disabled
15:32:34,366 INFO SettingsFactory:153 - Scrollable result sets: enabled
15:32:34,366 INFO SettingsFactory:161 - JDBC3 getGeneratedKeys(): disabled
15:32:34,366 INFO SettingsFactory:169 - Connection release mode: auto
15:32:34,366 INFO SettingsFactory:196 - Default batch fetch size: 1
15:32:34,366 INFO SettingsFactory:200 - Generate SQL with comments: disabled
15:32:34,366 INFO SettingsFactory:204 - Order SQL updates by primary key: disabled
15:32:34,366 INFO SettingsFactory:369 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
15:32:34,366 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
15:32:34,366 INFO SettingsFactory:212 - Query language substitutions: {}
15:32:34,366 INFO SettingsFactory:217 - JPA-QL strict compliance: disabled
15:32:34,366 INFO SettingsFactory:222 - Second-level cache: enabled
15:32:34,366 INFO SettingsFactory:226 - Query cache: disabled
15:32:34,366 INFO SettingsFactory:356 - Cache provider: org.hibernate.cache.NoCacheProvider
15:32:34,366 INFO SettingsFactory:241 - Optimize cache for minimal puts: disabled
15:32:34,366 INFO SettingsFactory:250 - Structured second-level cache entries: disabled
15:32:34,376 INFO SettingsFactory:270 - Echoing all SQL to stdout
15:32:34,376 INFO SettingsFactory:277 - Statistics: disabled
15:32:34,376 INFO SettingsFactory:281 - Deleted entity synthetic identifier rollback: disabled
15:32:34,376 INFO SettingsFactory:296 - Default entity-mode: pojo
15:32:34,447 INFO SessionFactoryImpl:161 - building session factory
15:32:34,777 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
15:32:34,777 INFO SchemaUpdate:115 - Running hbm2ddl schema update
15:32:34,777 INFO SchemaUpdate:126 - fetching database metadata
15:32:34,787 INFO SchemaUpdate:138 - updating schema
15:32:34,927 INFO TableMetadata:40 - table found: MPAC_MGR.USERS
15:32:34,927 INFO TableMetadata:41 - columns: [password, actions, name, id]
15:32:34,927 INFO TableMetadata:43 - foreign keys: []
15:32:34,927 INFO TableMetadata:44 - indexes: []
15:32:35,017 INFO TableMetadata:40 - table found: MPAC_MGR.WORKSTATIONS
15:32:35,027 INFO TableMetadata:41 - columns: [actions, id]
15:32:35,027 INFO TableMetadata:43 - foreign keys: []
15:32:35,027 INFO TableMetadata:44 - indexes: []
15:32:35,027 INFO SchemaUpdate:160 - schema update complete
15:32:35,148 DEBUG IntegerType:116 - returning null as column: ID1_0_
15:32:35,148 DEBUG IntegerType:116 - returning null as column: ID1_0_
15:32:35,148 DEBUG IntegerType:116 - returning null as column: ID1_0_
15:32:35,148 DEBUG IntegerType:116 - returning null as column: ID1_0_
15:32:35,148 DEBUG IntegerType:122 - returning '5' as column: ID1_0_
15:32:35,158 DEBUG StringType:122 - returning 'Freddie' as column: NAME1_0_
15:32:35,158 DEBUG StringType:122 - returning 'PICK,PACK' as column: ACTIONS1_0_
15:32:35,158 DEBUG StringType:122 - returning 'Flintstone' as column: PASSWORD1_0_
15:32:35,168 DEBUG IntegerType:122 - returning '5' as column: ID1_0_
(repeat the last line many times over - the number of times corresponds to the number of records in the database)
So my question is, what am I doing wrong?
I tracked down as many different examples as I could, but I am still not grasping what the problem is. (BTW - I'm new to Hibernate)