Hi,
I have the following problem: I have this class:
public class HRecordManager {
private Session session = null;
public HRecordManager(Session session)
{
if(session == null)
throw new RuntimeException("Invalid session object. Cannot instantiate the UserManager");
this.session = session;
}
public void saveRecord(RequestRecord record){
session.beginTransaction();
session.persist(record);
}
and the mapping for the RequestRecord class:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="ibm.request">
<class name="RequestRecord" table="RR">
<id
name="id"
column="RR_ID">
<generator class="native"/>
</id>
<property
name="requester"
column="REQUESTER">
</property>
<property
name="skills"
column="SKILLS">
</property>
<property
name="answerDate"
column="ANSWERDATE">
</property>
<property
name="receiveDate"
column="RECEIVEDATE"/>
<property
name="description"
column="DESCRIPTION">
</property>
<list name="rrlList" table="RRL" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column = "RR_ID" not-null="true"/>
<list-index
column="IND"/>
<one-to-many
class="RequestRecordLine"/>
</list>
</class>
</hibernate-mapping>
Then I test the HRecordManager with:
public class HRecordManagerTest {
public RequestRecord buildRR(){
RequestRecord rr = new RequestRecord();
rr.setSkills("some skills");
rr.setDescription("description");
rr.setAnswerDate("answerDate");
rr.setReceiveDate("receiveDate");
return rr;
}
public Session openSession(){
Configuration config = new Configuration();
SessionFactory sessionFactory = config.configure().buildSessionFactory();
Session session =sessionFactory.openSession();
return session;
}
public RequestRecord testSaveRecord(HRecordManager manager) {
RequestRecord record = buildRR();
manager.saveRecord(record);
System.out.println("Record saved with ID = "+ record.getId());
return record;
}
public static void main(String[] args) {
HRecordManagerTest test = new HRecordManagerTest();
Session session = test.openSession();
HRecordManager manager = new HRecordManager(session);
RequestRecord rr=test.testSaveRecord(manager);
session.flush();
}
When I run it everything seems Ok and this is the result i get:
12:50:32,010 INFO Environment:514 - Hibernate 3.2.6
12:50:32,020 INFO Environment:547 - hibernate.properties not found
12:50:32,030 INFO Environment:681 - Bytecode provider name : cglib
12:50:32,040 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
12:50:32,140 INFO Configuration:1432 - configuring from resource: /hibernate.cfg.xml
12:50:32,150 INFO Configuration:1409 - Configuration resource: /hibernate.cfg.xml
12:50:32,320 INFO Configuration:559 - Reading mappings from resource : ibm/request/Contractor.hbm.xml
12:50:32,531 INFO HbmBinder:300 - Mapping class: ibm.request.Contractor -> C_DB
12:50:32,551 INFO Configuration:559 - Reading mappings from resource : ibm/request/Contractors.hbm.xml
12:50:32,601 INFO HbmBinder:300 - Mapping class: ibm.request.Contractors -> CONTRACTORS
12:50:32,671 INFO Configuration:559 - Reading mappings from resource : ibm/request/RequestRecord.hbm.xml
12:50:32,701 INFO HbmBinder:300 - Mapping class: ibm.request.RequestRecord -> RR
12:50:32,711 INFO Configuration:559 - Reading mappings from resource : ibm/request/RequestRecordLine.hbm.xml
12:50:32,751 INFO HbmBinder:300 - Mapping class: ibm.request.RequestRecordLine -> RRL
12:50:32,751 INFO Configuration:1547 - Configured SessionFactory: null
12:50:32,761 INFO HbmBinder:2382 - Mapping collection: ibm.request.RequestRecord.rrlList -> RRL
12:50:32,761 INFO HbmBinder:2382 - Mapping collection: ibm.request.RequestRecordLine.contractors -> CONTRACTORS
12:50:32,791 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
12:50:32,791 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
12:50:32,791 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
12:50:32,941 INFO DriverManagerConnectionProvider:80 - using driver: com.ibm.db2.jcc.DB2Driver at URL: jdbc:db2://9.157.146.107:50000/CRM_GPSG
12:50:32,941 INFO DriverManagerConnectionProvider:86 - connection properties: {user=db2admin, password=****}
12:50:33,232 INFO SettingsFactory:89 - RDBMS: DB2/NT, version: SQL08028
12:50:33,232 INFO SettingsFactory:90 - JDBC driver: IBM DB2 JDBC Universal Driver Architecture, version: 3.50.152
12:50:33,272 INFO Dialect:152 - Using dialect: org.hibernate.dialect.DB2Dialect
12:50:33,282 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
12:50:33,282 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
12:50:33,292 INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
12:50:33,292 INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
12:50:33,292 INFO SettingsFactory:162 - Scrollable result sets: enabled
12:50:33,292 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): enabled
12:50:33,292 INFO SettingsFactory:178 - Connection release mode: auto
12:50:33,292 INFO SettingsFactory:205 - Default batch fetch size: 1
12:50:33,292 INFO SettingsFactory:209 - Generate SQL with comments: disabled
12:50:33,292 INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
12:50:33,292 INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
12:50:33,292 INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
12:50:33,302 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
12:50:33,302 INFO SettingsFactory:225 - Query language substitutions: {}
12:50:33,302 INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
12:50:33,302 INFO SettingsFactory:235 - Second-level cache: enabled
12:50:33,302 INFO SettingsFactory:239 - Query cache: disabled
12:50:33,302 INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
12:50:33,302 INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
12:50:33,302 INFO SettingsFactory:263 - Structured second-level cache entries: disabled
12:50:33,312 INFO SettingsFactory:290 - Statistics: disabled
12:50:33,312 INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
12:50:33,312 INFO SettingsFactory:309 - Default entity-mode: pojo
12:50:33,312 INFO SettingsFactory:313 - Named query checking : enabled
12:50:33,362 INFO SessionFactoryImpl:161 - building session factory
12:50:33,923 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
Record saved with ID = 162
Record updated with ID = 162
The problem is that when I open the database there are no records in it. How can i fix it?
Hibernate version:3.2
Name and version of the database you are using:DB2
|