Announcement Announcement Module
No announcement yet.
Strange error when using Hibernate Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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"


    <class name="businessLayer.Project" table="project">
    <id name="id" column="id" type="java.lang.Integer">
    <generator class="native"/>
    <property name="ProjectId" type="java.lang.Integer"/>
    <property name="ProjectNumber" type="java.lang.Integer"/>
    <property name="ProjectName" type="java.lang.String"/>


  • #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)?




    • #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"?


      • #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=""

        <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 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 name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>



        • #5

          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?



          • #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();

            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"

            <!-- 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="">create</property>

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

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



            I have to test insert from query browser.


            • #7
              Just one thought:

              <!-- Drop and recreate db schema on startup -->
              <property name="">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?