I was using the following code to insert a row in the database using Hibernate framework.
public static void main(
String[] args)
{
Session session = null;
SessionFactory sf=null;
try
{
sf = new Configuration().configure().buildSessionFactory();
session =sf.openSession();
dbtable table = new dbtable();
table.setRoll(12);
table.setFirstName("ab");
table.setLastName("yz");
table.setMail("
[email protected]");
session.save(table);
System.out.println("Done");
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
finally
{
session.flush();
session.close();
}
}
Here dbtable is a
java bean class with getters and setters for the columns of the table.
I am using the following in hiberbate.cfg.xml file
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">
jdbc
racle:thin:@<IPaddress>:<port>:hrqa115g</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">pwd</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="dbmapping.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The dbmapping.hbm.xml file has the following:
<hibernate-mapping>
<class name="a.b.dbtable" table="info">
<id name="roll" type="long" column="roll">
<generator class="native"/> </id>
<property name="firstName" column="fname" type="java.lang.String" update="true" insert="true"/>
<property name="lastName" column="lname" type="java.lang.String" update="true" insert="true"/>
<property name="mail" column="mail" type="java.lang.String" update="true" insert="true"/>
</class>
</hibernate-mapping>
When I execute the java code, I am not getting any error. After execution, when I check in the table, I get "0 rows returned".
Any help on my issue will be appreciated. Looking for your valuable response.