Hello professor,
When I tested your userDao example the test worked. I simply changed the code in your examples and implemented tests for my csjobs and ran it, and it showed me this.
Jul 16, 2015 10:10:28 AM org.springframework.test.context.support.DefaultTestContextBootstrapper getTestExecutionListeners
INFO: Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@6eebc39e, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@464bee09, org.springframework.test.context.support.DirtiesContextTestExecutionListener@f6c48ac, org.springframework.test.context.transaction.TransactionalTestExecutionListener@13deb50e, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@239963d8]
[TestNG] Running:
C:\Users\Sam\AppData\Local\Temp\testng-eclipse-1258413260\testng-customsuite.xml
Jul 16, 2015 10:10:28 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Jul 16, 2015 10:10:29 AM org.springframework.context.support.GenericApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.GenericApplicationContext@7a1ebcd8: startup date [Thu Jul 16 10:10:29 PDT 2015]; root of context hierarchy
Jul 16, 2015 10:10:30 AM org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean createNativeEntityManagerFactory
INFO: Building JPA container EntityManagerFactory for persistence unit 'springmvc'
Jul 16, 2015 10:10:30 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Jul 16, 2015 10:10:30 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.19.Final}
Jul 16, 2015 10:10:30 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 16, 2015 10:10:30 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 16, 2015 10:10:30 AM org.hibernate.ejb.Ejb3Configuration configure
INFO: HHH000204: Processing PersistenceUnitInfo [
name: springmvc
...]
Jul 16, 2015 10:10:31 AM org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator instantiateExplicitConnectionProvider
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
Jul 16, 2015 10:10:32 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
Jul 16, 2015 10:10:32 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Jul 16, 2015 10:10:33 AM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: springmvc.model.Reviewer
Jul 16, 2015 10:10:33 AM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: springmvc.model.Admin
Jul 16, 2015 10:10:33 AM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: springmvc.model.Applicant
Jul 16, 2015 10:10:33 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Jul 16, 2015 10:10:33 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Jul 16, 2015 10:10:34 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Hibernate: alter table Evaluation drop constraint FK_s6g5lmu0u2dp37q01hte556xf
Hibernate: alter table Evaluation drop constraint FK_9ks89ogmslrggokt5nc67caw9
Hibernate: alter table job_application_education_list drop constraint FK_l6b11v2bkqgti64r3ajtra0qj
Hibernate: alter table job_applications drop constraint FK_suqo4dnhrkf0w3spog62gopua
Hibernate: alter table job_applications drop constraint FK_740jd4s98demifcogu1atf7dn
Hibernate: alter table job_positions_applicants drop constraint FK_e6rupblxvjppstmsso3ujo69h
Hibernate: alter table job_positions_applicants drop constraint FK_b5fvxjtdh6f2mph2jp6213hr2
Hibernate: alter table job_positions_reviewers drop constraint FK_pt4jhavxbfypyq285byu9iuok
Hibernate: alter table job_positions_reviewers drop constraint FK_ry4ohpu5d9mmkj2d9715rofcx
Hibernate: drop table if exists Evaluation cascade
Hibernate: drop table if exists job_application_education_list cascade
Hibernate: drop table if exists job_applications cascade
Hibernate: drop table if exists job_positions cascade
Hibernate: drop table if exists job_positions_applicants cascade
Hibernate: drop table if exists job_positions_reviewers cascade
Hibernate: drop table if exists users cascade
Hibernate: drop sequence hibernate_sequence
Hibernate: create table Evaluation (id int4 not null, score int4 not null, application_id int4, reviewer_id int4, primary key (id))
Hibernate: create table job_application_education_list (job_application_id int4 not null, degree varchar(255), school varchar(255), year int4)
Hibernate: create table job_applications (id int4 not null, company varchar(255), title varchar(255), year varchar(255), applicant_id int4, jobPosition_id int4, primary key (id))
Hibernate: create table job_positions (id int4 not null, close_date timestamp, description varchar(255), publish_date timestamp, title varchar(255), primary key (id))
Hibernate: create table job_positions_applicants (job_position_id int4 not null, applicant_id int4 not null)
Hibernate: create table job_positions_reviewers (job_position_id int4 not null, reviewer_id int4 not null)
Hibernate: create table users (user_type varchar(31) not null, id int4 not null, email varchar(255) not null, first_name varchar(255), last_name varchar(255), password varchar(255) not null, city varchar(255), state varchar(255), street varchar(255), zipcode varchar(255), phone varchar(255), primary key (id))
Hibernate: alter table users add constraint UK_6dotkott2kjsp8vw4d0m25fb7 unique (email)
Hibernate: alter table Evaluation add constraint FK_s6g5lmu0u2dp37q01hte556xf foreign key (application_id) references job_applications
Hibernate: alter table Evaluation add constraint FK_9ks89ogmslrggokt5nc67caw9 foreign key (reviewer_id) references users
Hibernate: alter table job_application_education_list add constraint FK_l6b11v2bkqgti64r3ajtra0qj foreign key (job_application_id) references job_applications
Hibernate: alter table job_applications add constraint FK_suqo4dnhrkf0w3spog62gopua foreign key (applicant_id) references users
Hibernate: alter table job_applications add constraint FK_740jd4s98demifcogu1atf7dn foreign key (jobPosition_id) references job_positions
Hibernate: alter table job_positions_applicants add constraint FK_e6rupblxvjppstmsso3ujo69h foreign key (applicant_id) references users
Hibernate: alter table job_positions_applicants add constraint FK_b5fvxjtdh6f2mph2jp6213hr2 foreign key (job_position_id) references job_positions
Hibernate: alter table job_positions_reviewers add constraint FK_pt4jhavxbfypyq285byu9iuok foreign key (reviewer_id) references users
Hibernate: alter table job_positions_reviewers add constraint FK_ry4ohpu5d9mmkj2d9715rofcx foreign key (job_position_id) references job_positions
Hibernate: create sequence hibernate_sequence
Jul 16, 2015 10:10:36 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Jul 16, 2015 10:10:37 AM org.springframework.test.context.transaction.TransactionContext startTransaction
INFO: Began transaction (1) for test context [DefaultTestContext@63034ed1 testClass = UserDaoTest, testInstance = springmvc.model.dao.UserDaoTest@6e1ec318, testMethod = getUser@UserDaoTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@232024b9 testClass = UserDaoTest, locations = '{classpath:applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@55a8dc49]; rollback [true]
Hibernate: select user0_.id as id2_6_0_, user0_.email as email3_6_0_, user0_.first_name as first_na4_6_0_, user0_.last_name as last_nam5_6_0_, user0_.password as password6_6_0_, user0_.city as city7_6_0_, user0_.state as state8_6_0_, user0_.street as street9_6_0_, user0_.zipcode as zipcode10_6_0_, user0_.phone as phone11_6_0_, user0_.user_type as user_typ1_6_0_ from users user0_ where user0_.id=?
Jul 16, 2015 10:10:38 AM org.springframework.test.context.transaction.TransactionContext endTransaction
INFO: Rolled back transaction for test context [DefaultTestContext@63034ed1 testClass = UserDaoTest, testInstance = springmvc.model.dao.UserDaoTest@6e1ec318, testMethod = getUser@UserDaoTest, testException = java.lang.NullPointerException, mergedContextConfiguration = [MergedContextConfiguration@232024b9 testClass = UserDaoTest, locations = '{classpath:applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]].
Jul 16, 2015 10:10:38 AM org.springframework.test.context.transaction.TransactionContext startTransaction
INFO: Began transaction (1) for test context [DefaultTestContext@63034ed1 testClass = UserDaoTest, testInstance = springmvc.model.dao.UserDaoTest@6e1ec318, testMethod = getUsers@UserDaoTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@232024b9 testClass = UserDaoTest, locations = '{classpath:applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@55a8dc49]; rollback [true]
Jul 16, 2015 10:10:38 AM org.springframework.test.context.transaction.TransactionContext endTransaction
INFO: Rolled back transaction for test context [DefaultTestContext@63034ed1 testClass = UserDaoTest, testInstance = springmvc.model.dao.UserDaoTest@6e1ec318, testMethod = getUsers@UserDaoTest, testException = org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped [from users]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped [from users], mergedContextConfiguration = [MergedContextConfiguration@232024b9 testClass = UserDaoTest, locations = '{classpath:applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]].
FAILED: getUser
java.lang.NullPointerException
at springmvc.model.dao.UserDaoTest.getUser(UserDaoTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:200)
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:171)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:212)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:652)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:845)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1153)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:771)
at org.testng.TestRunner.run(TestRunner.java:621)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1199)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1124)
at org.testng.TestNG.run(TestNG.java:1032)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
I got a nullpointer exception, I checked the table and all the data in my table got wiped out. (my sql files work fine).
Can you give me any suggestions?