Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate / Spring rolling back insert without error
    primarykey
    data
    text
    <p>I've got 2 classes, Foo and FooType where FooType is just 3 rows in the database representing the 3 possible types. I do map FooType in Hibernate but there's nothing besides the ID and description fields. There's no mapping back to Foo in the FooType hbm file. </p> <p>In Foo, I have a many-to-one mapping since each Foo needs to have a Type.</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.blah.domain.Foo" table="foos" lazy="false"&gt; &lt;id name="id" type="int"&gt; &lt;column name="id" /&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;many-to-one name="type" class="com.blah.domain.FooType" column="type" not-null="true" unique="false" update="false" fetch="join"/&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>Here's the relevant bit of my Spring config</p> <pre><code>&lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory"&gt;&lt;ref local="sessionFactory"/&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="configLocation"&gt; &lt;value&gt;WEB-INF/hibernate.cfg.xml&lt;/value&gt; &lt;/property&gt; &lt;property name="mappingResources"&gt; &lt;list&gt; &lt;value&gt;com/secretry/domain/Foo.hbm.xml&lt;/value&gt; &lt;value&gt;com/secretry/domain/FooType.hbm.xml&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>I think this is correct but if not please help. I have a FooDao that uses the HibernateDaoSupport for transactions.</p> <pre><code>public class FoonDao extends HibernateDaoSupport implements IFooDao { private IFooTypeDao fooTypeDao; @Override public Foo createFoo(String name, String description, int fooTypeId) { FooType type = fooTypeDao.getFooType(fooTypeId); Foo newFoo = new Foo(name, description, type); try { getHibernateTemplate().save(newFoo); } catch(Exception e) { logger.error("ERROR: ", e); return null; } return newFoo; } } </code></pre> <p>When I run createFoo, I don't see any errors but in my MySQL logs I see the <code>Insert</code> statement followed immediately by a <code>rollback</code>. I have full logging turned on for Hibernate but I don't see anything that strikes me as an error. When I copy the insert out of the logs and run it in mysql manually, <strong>it works fine</strong>, which is probably the most confounding thing.</p> <p>I'm new to Hibernate so I guess it's probably something I'm doing wrong with the many-to-one mapping but I cannot figure this out for the life of me. Any help with the problem or direction on what I might be doing wrong would be massively appreciated. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload