[hibernate-dev] Insert not working

Max Rydahl Andersen max.andersen at jboss.com
Wed Aug 30 13:08:37 EDT 2006


http://forum.hibernate.org

/max

> 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
>



-- 
--
Max Rydahl Andersen
callto://max.rydahl.andersen

Hibernate
max at hibernate.org
http://hibernate.org

JBoss a division of Red Hat
max.andersen at jboss.com




More information about the hibernate-dev mailing list