Announcement Announcement Module
Collapse
No announcement yet.
Strange error when using Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange error when using Hibernate

    I'm really new to Hibernate. I use both Spring and Hibernate. I am almost finished with my test application. Everything works fine and I see with MySQL Query Browser that records will be inserted into the database from my Web browser. I have also made a web page that reads records from my database and I see all my insterted records in that web page.

    Now, to the strange part!

    After a while - maybe 5-10 minutes all my inserted data will disappear from the database. Why? Can someone help med describe that? Is autocommit turned off? Some default value that must be changed?

    This is my mapping file;

    <?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="businessLayer.Project" table="project">
    <id name="id" column="id" type="java.lang.Integer">
    <generator class="native"/>
    </id>
    <property name="ProjectId" type="java.lang.Integer"/>
    <property name="ProjectNumber" type="java.lang.Integer"/>
    <property name="ProjectName" type="java.lang.String"/>
    </class>

    </hibernate-mapping>

  • #2
    you will have to provide more information. Please provide your application context file.

    How do you define your transactions? Are you using myisam or innodb tables (check in the mysql admin tool)?

    Cheers

    G

    Comment


    • #3
      This is really weird. Never saw that before. What I realize is, that your ID is from type Integer. Shouldn't it be type="java.lang.Long"?

      Comment


      • #4
        More information

        Well I use innodb tables. I have checked that as you suggested Goran!

        Here is my application_context file;

        <?xml version="1.0" encoding="UTF-8"?>

        <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

        <bean name="/createProject.htm" class="businessLayer.controller.CreateProjectContr oller">
        <property name="sessionForm" value="true"/>
        <property name="formView" value="createProject"/>
        <property name="projectService" ref="projectService"/>
        </bean>

        <bean id="projectService" class="businessLayer.service.ProjectServiceImpl"></bean>

        <bean name="/readProject.htm" class="businessLayer.controller.ReadProjectControl ler"></bean>
        <bean name="/updateProject.htm" class="businessLayer.controller.UpdateProjectContr oller"></bean>
        <bean name="/deleteProject.htm" class="businessLayer.controller.DeleteProjectContr oller"></bean>

        <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
        <property name="viewClass">
        <value>org.springframework.web.servlet.view.JstlVi ew</value>
        </property>
        <property name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>
        </bean>

        </beans>

        Comment


        • #5
          Ok,

          I'm kind of after the files where you define your data source, transactions etc.

          1. Are you using hibernate directly without Spring integration? If that's the case, please provide the code where you insert a record into your db, including the bit that defines your transaction boundary.

          2. Insert some records directly from the query browser. Are they disappearing?

          G

          Comment


          • #6
            I use Hibernate directly without Spring integration.

            This is how I save a record to the database in my DAO object;

            Transaction transaction = hibernateSession.beginTransaction();
            hibernateSession.save(project);
            transaction.commit();

            This is my Hibernate.cfg.xml file;

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

            <hibernate-configuration>
            <session-factory>
            <!-- Database connection settings -->
            <property name="connection.driver_class">com.mysql.jdbc.Driv er</property>
            <property name="connection.url">jdbc:mysql://localhost:3306/agiobelplan</property>
            <property name="connection.username">root</property>
            <property name="connection.password">enr8ienp8</property>

            <!-- JDBC connection pool -->
            <property name="connection.pool_size">1</property>

            <!-- SQL Dialect -->
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

            <!-- Session context management -->
            <property name="current_session_context_class">thread</property>

            <!-- Disable 2nd level cache -->
            <property name="cache.provider_class">org.hibernate.cache.No CacheProvider</property>

            <!-- Echo all sql to sdtout -->
            <property name="show_sql">false</property>

            <!-- Drop and recreate db schema on startup -->

            <property name="hbm2ddl.auto">create</property>

            <!-- List all the Java classes we have mapped here -->

            <mapping resource="Project.hbm.xml"/>

            </session-factory>

            </hibernate-configuration>

            I have to test insert from query browser.

            Comment


            • #7
              Just one thought:

              <!-- Drop and recreate db schema on startup -->
              <property name="hbm2ddl.auto">create</property>

              is part of your cfg file, i.e. the schema will be recreated and data lost, each time you restart your application. Is this the behavior you see?

              G

              Comment

              Working...
              X