[hibernate-dev] Insert not working

Dinesh Chaturvedi dineshchaturvedi at gmail.com
Wed Aug 30 12:52:44 EDT 2006


Hi,
I have just started working on hibernate. I was trying to start with some
sample applications.
I am facing this problem when I am trying to insert data. It does not throw
any error but does not do any insert.
I can easily fetch information using the same mapping.

Can someone help me with this.
I am using MYSQL5 with hibernate 3

My hibernate-cfg.xml loooks like following
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
      <property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url
">jdbc:mysql://localhost/test</property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.password"></property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <!-- Mapping files -->
      <mapping resource="contact.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

my contact.hbm.xml looks like

<?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>
  <class name="com.test.dbo.contact" table="contacts">
       <id name="id" type="long" column="id" >
        <generator class="increment"/>
      </id>
      <property name="email">
         <column name="email" />
      </property>
      <property name="modified_date">
        <column name="modified_date"/>
      </property>
   </class>
</hibernate-mapping>

The Java Code looks like the following
SessionFactory factory = null;
         try
         {
             Configuration cfg = new Configuration();
             factory = cfg.configure().buildSessionFactory();
              Session  session =  factory.openSession();
              notification_email ne = createNotificationEmail();
              session.save(ne);
              session.flush();
              session.close();
         }
         catch(Exception e)
         {
             System.out.println(""+e);
             e.printStackTrace();
         }

I will greatly appreciate if someone can provide me an answer. Really
struggling. thanks

-- 
Dinesh Chaturvedi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-dev/attachments/20060830/4e25e932/attachment.html 


More information about the hibernate-dev mailing list