Hi,
Now that i have successfully setup hibernate configs, still No Record is getting inserted in the db table abc_1412 after that SQL (it replaced values passed in java file with question marks as shown in Hibernate SQL log below). Though it successfully finds the required tables / fields (ref: see log below). as shown in the log below.
I want to insert the record!!
Hibernate version: 3.1
Mapping documents:
Code:
<class name="tutorial.hibernate.Contact" table="CONTACT">
<id name="id" type="long" column="ID" >
<generator class="assigned"/>
</id>
<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
<class name="tutorial.hibernate.Book" table="book">
<id name="lngBookId" type="long" column="id" >
<generator class="increment"/>
</id>
<property name="strBookName">
<column name="bookname" />
</property>
</class>
<class name="tutorial.hibernate.Insurance" table="insurance">
<id name="lngInsuranceId" type="long" column="ID" >
<generator class="increment"/>
</id>
<property name="insuranceName">
<column name="insurance_name" />
</property>
<property name="investementAmount">
<column name="invested_amount" />
</property>
<property name="investementDate">
<column name="investement_date" />
</property>
</class>
Code between sessionFactory.openSession() and session.close():Code:
try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(6);
contact.setFirstName("Fee");
contact.setLastName("Lee");
contact.setEmail("flee@yahoo.com");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
Full stack trace of any exception that occurs:No exceptions
Name and version of the database you are using:Oracle 8i
The generated SQL (show_sql=true):Code:
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
Debug level Hibernate log excerpt:Code:
15:51:08,515 INFO TableMetadata:38 - table found: ABC_1412.CONTACT
15:51:08,515 INFO TableMetadata:39 - columns: [lastname, firstname, email, id]
15:51:08,515 INFO TableMetadata:40 - foreign keys: []
15:51:08,515 INFO TableMetadata:41 - indexes: []
15:51:08,765 INFO TableMetadata:38 - table found: ABC_1412.BOOK
15:51:08,765 INFO TableMetadata:39 - columns: [bookname, id]
15:51:08,765 INFO TableMetadata:40 - foreign keys: []
15:51:08,765 INFO TableMetadata:41 - indexes: []
15:51:08,937 INFO TableMetadata:38 - table found: ABC_1412.INSURANCE
15:51:08,937 INFO TableMetadata:39 - columns: [insurance_name, invested_amount, investement_date, id]
15:51:08,937 INFO TableMetadata:40 - foreign keys: []
15:51:08,937 INFO TableMetadata:41 - indexes: []
15:51:08,937 INFO SchemaUpdate:153 - schema update complete
15:51:08,953 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:oracle:thin:@localhost:1521:cs
15:51:08,953 INFO SessionFactoryImpl:366 - Checking 0 named queries
Inserting Record
Done
15:51:09,046 DEBUG SQL:292 - insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)