facebook

Hibernate + Spring + DOA generation save not working

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #260814 Reply

    rbrand
    Member

    Hi

    Tried created a simple table:

    testtable  CREATE TABLE `testtable` (                        
                 `id` int(10) unsigned NOT NULL auto_increment,  
                 `text` char(30) NOT NULL,                       
                 PRIMARY KEY  (`id`)                             
               ) ENGINE=InnoDB DEFAULT CHARSET=latin1            
    

    From there I created a webService Project, Added Spring Capabilities, added Hibernate Capabilities and then mapped above table to using Hibernate. I used the Spring DOA generation and ‘identity’ for the id generator. So the mapping looks like this:

    <hibernate-mapping>
        <class name="com.client.crm.db.Testtable" table="testtable">
            <id name="id" type="java.lang.Integer">
                <column name="id" />
                <generator class="identity" />
            </id>
            <property name="text" type="java.lang.String">
                <column name="text" length="30" not-null="true" />
            </property>
        </class>
    </hibernate-mapping>

    The save function in the DOA looks as follows

    
        public void save(Testtable transientInstance) {
            log.debug("saving Testtable instance");
            try {
                getHibernateTemplate().save(transientInstance);
                log.debug("save successful");
            } catch (RuntimeException re) {
                log.error("save failed", re);
                throw re;
            }
        }
    

    All pretty standard stuff. Then I tried to save an object, with no effect. I can see that each time I save an object, the id increases by one, but when I look at the DB, there is nothing, nada.

    I had the same problem before using Spring and then found (after some help from some friendly hiberate people, that when I wrap the save in a transaction it works.

    I have used Spring and Hibernate before, but not with MyEclipse and not with Transactions. It worked then, why not now?

    Thanks-

    rbrand

    System Setup ——————————-
    Operating System and version: WinXP
    Eclipse version: 3.2
    Eclipse build id:
    Fresh Eclipse install (y/n): y
    If not, was it upgraded to its current version using the update manager?
    Other installed external plugins:
    Number of plugins in the <eclipse>/plugins directory that begin with org.eclipse.pde.*:
    MyEclipse version: 5.0.1 GA
    Eclipse JDK version:
    Application Server JDK version:
    Are there any exceptions in the Eclipse log file?

    If this is a DB related question please answer the following:

    RDBMS vendor and version: MySql, 5.0.22-community-nt
    JDBC driver vendor and version, and access type (thin, type-2, etc):
    Connection URL:
    Eclipse error logs related to com.genuitec.eclipse.sqlexplorer packages:

    #260816 Reply

    Haris Peco
    Member

    rbrand,
    You have to use hibernate transaction API or (easier) spring’s hibernate interceptor.See this thread for details
    http://myeclipseide.com/modules.php?op=modload&name=PNphpBB2&file=viewtopic&t=13190

    You can see next link , too http://www.jroller.com/page/kbaum?entry=orm_lazy_initialization_with_dao

    regards,

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Hibernate + Spring + DOA generation save not working

You must be logged in to post in the forum log in