hi,
i try to use hibernate 2.1.6 and c3p0 with HSQLDB. I wrote a JUnit testcase to insert some data into the database. Although the testcase passes without error message, there is no data saved to the database. Here is the message generated by hibernate during the execution of the testcase:
(cfg.Environment 469 ) Hibernate 2.1.6
(cfg.Environment 498 ) hibernate.properties not found
(cfg.Environment 529 ) using CGLIB reflection optimizer
(cfg.Configuration 895 ) configuring from resource: /hibernate.cfg.xml
(cfg.Configuration 867 ) Configuration resource: /hibernate.cfg.xml
(cfg.Configuration 331 ) Mapping resource: de/soccermanager/person/entity/Person.hbm.xml
(cfg.Binder 229 ) Mapping class: de.soccermanager.person.entity.Person -> PERSON
(cfg.Binder 200 ) Mapping joined-subclass: de.soccermanager.person.entity.TeamManager -> TEAM_MANAGER
(cfg.Binder 200 ) Mapping joined-subclass: de.soccermanager.person.entity.Player -> PLAYER
(cfg.Configuration 331 ) Mapping resource: de/soccermanager/person/entity/Address.hbm.xml
(cfg.Binder 229 ) Mapping class: de.soccermanager.person.entity.Address -> ADDRESS
(cfg.Configuration 331 ) Mapping resource: de/soccermanager/team/entity/Team.hbm.xml
(cfg.Binder 229 ) Mapping class: de.soccermanager.team.entity.Team -> TEAM
(cfg.Configuration 1053) Configured SessionFactory: null
(cfg.Configuration 627 ) processing one-to-many association mappings
(cfg.Binder 1181) Mapping collection: de.soccermanager.person.entity.TeamManager.listManagedTeams -> TEAM
(cfg.Binder 1181) Mapping collection: de.soccermanager.team.entity.Team.players -> PLAYER
(cfg.Configuration 636 ) processing one-to-one association property references
(cfg.Configuration 661 ) processing foreign key constraints
(dialect.Dialect 82 ) Using dialect: net.sf.hibernate.dialect.HSQLDialect
(cfg.SettingsFactory 63 ) Use outer join fetching: true
(connection.C3P0ConnectionProvider 48 ) C3P0 using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost/mytestdbhibi
(connection.C3P0ConnectionProvider 49 ) Connection properties: {user=sa, password=}
(transaction.TransactionManagerLookupFactory 33 ) No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@10a6ae2 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@90cb03 [ acquireIncrement -> 1, autoCommitOnClose -> false, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxIdleTime -> 300, maxPoolSize -> 20, maxStatements -> 50, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@ef2c60 [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:hsqldb:hsql://localhost/mytestdbhibi, properties -> {user=sa, password=} ] , propertyCycle -> 300, testConnectionOnCheckout -> false ] , factoryClassLocation -> null, numHelperThreads -> 3 ]
(cfg.SettingsFactory 103 ) Use scrollable result sets: true
(cfg.SettingsFactory 106 ) Use JDBC3 getGeneratedKeys(): false
(cfg.SettingsFactory 109 ) Optimize cache for minimal puts: false
(cfg.SettingsFactory 115 ) echoing all SQL to stdout
(cfg.SettingsFactory 118 ) Query language substitutions: {}
(cfg.SettingsFactory 129 ) cache provider: net.sf.hibernate.cache.EhCacheProvider
(cfg.Configuration 1116) instantiating and configuring caches
(impl.SessionFactoryImpl 118 ) building session factory
(impl.SessionFactoryObjectFactory 82 ) Not binding factory to JNDI, no JNDI name configured
Hibernate: insert into PERSON (ADDRESS_ID, NATIONALITY, GENDER, ATTITUDE, HEALTHINESS, MORALITY, RELIABLENESS, SELFCONFIDENCE, DATEOFBIRTH, FIRSTNAME, LASTNAME, PERSON_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, null)
Hibernate: call identity()
Hibernate: insert into PLAYER (TEAM_ID, POSITION, CONTRACT_PERIOD, SALARY, PLAYER_ID) values (?, ?, ?, ?, ?)
Hibernate: insert into TEAM (TEAM_NAME, TEAM_ID) values (?, null)
Hibernate: call identity()
AutoCommit is set off. I have no idea what could be wrong!? I am using the session-local-thread-pattern and created two simple DAO's to insert a player object and a team object.
my testcase class:
public class TestInsertData extends TestCase {
Player player = new Player();
Address address = new Address();
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
player.setStrFirstName("Michael");
player.setStrLastName("Ballack");
player.setDateOfBirth(new Date()); //for testing
player.setIntAttitude(100);
player.setGender(Gender.MALE); //User-Type
player.setIntHealthiness(99);
player.setIntMorality(98);
player.setIntMonthlySalary(50000);
player.setIntNationality(Constant.INT_NATIONALITY_GERMAN);
player.setIntPosition(3);
player.setIntContractPeriod(24);
player.setIntReliableness(97);
player.setIntSelfConfidence(96);
address.setStrStreet("unknown");
address.setStrStreetNumber("unknown");
address.setStrPostalCode("unknown");
address.setStrCity("unknown");
address.setStrCountry("unknown");
address.setStrEmail("unknown");
address.setStrHomePhone("unknown");
address.setStrMobilePhone("unknown");
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* Constructor for TestInsertData.
* @param name
*/
public TestInsertData(String name) {
super(name);
}
public void testInsertPlayer() throws InfrastructureException{
PersonDAO personDAO = new PersonDAO();
personDAO.insertNewPerson(player);
HibernateUtil.commitTransaction();
}
public void testInsertTeam() throws InfrastructureException{
TeamDAO teamDAO = new TeamDAO();
Team team = new Team();
team.setStrTeamName("FC Barcelona");
teamDAO.insertNewTeam(team);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
}
}
My DAOs:
public class PersonDAO {
public PersonDAO() throws InfrastructureException {
super();
HibernateUtil.beginTransaction();
}
public Person getPersonById(Long personId) throws InfrastructureException{
Session session = HibernateUtil.getSession();
Person person = null;
try{
person = (Person)session.load(Person.class, personId);
}catch(HibernateException ex){
throw new InfrastructureException(ex);
}
return person;
}
public void insertNewPerson(Player person) throws InfrastructureException{
Session session = HibernateUtil.getSession();
try{
session.save(person);
}catch(HibernateException ex){
throw new InfrastructureException(ex);
}
}
}
public class TeamDAO {
public TeamDAO() throws InfrastructureException {
super();
HibernateUtil.beginTransaction();
}
public void insertNewTeam(Team team) throws InfrastructureException{
Session session = HibernateUtil.getSession();
try{
session.save(team);
}catch(HibernateException ex){
throw new InfrastructureException(ex);
}
}
}
Where is the mistake? Thanks for helping me.
Sven
|