Bug Day on Hibernate Module !
Par Jérôme le mercredi 20 août 2008, 13:57 - IDM/MDE... - Lien permanent
This morning, i tracked strange bug on the Acceleo Hibernate module :
__________________ ______________________
| CLASS_MANY_01_BI |<-- * {-} 1 -->| CLASS_MANY_01_BI_END |
|__________________| |______________________|
The generator created this bloc in Class_Many_01_BI_END.hbm.xml :
<set name="source" inverse="true">
<key column="FK__TARGET_ID"/>
<one-to-many class="org.acceleo.hibernate.bug.entities.Class_Many_01_BI"/>
</set>
But the correct mapping seems to be :
<set name="source" inverse="true">
<key column="FK_CLASS_MANY_01_BI_END_TARGET_ID"/>
<one-to-many class="org.acceleo.hibernate.bug.entities.Class_Many_01_BI"/>
</set>
I wrote a basic unit test to detect the problem :
@Test public void testMany_01_BI() throws Exception{
Class_Many_01_BI_END target = new Class_Many_01_BI_END();
getSession().save(target);
Class_Many_01_BI source = new Class_Many_01_BI();
source.setTarget(target);
getSession().save(source);
getSession().flush();
getSession().clear();
target = (Class_Many_01_BI_END)getSession().load(Class_Many_01_BI_END.class, target.getId());
assertNotNull(target);
assertNotNull(target.getSource());
assertEquals("Bad mapping detected!", 1, target.getSource().size());
}
And after short debate on #acceleo IRC channel, thanks Gougou, i added my fix on trunk here :
svn diff -r1655:1656 svn://svn.forge.objectweb.org/svnroot/acceleo/trunk/modules/community/uml21/jee/trunk
This problem gives me to think how to improve this module. The
"org.acceleo.module.pim.uml21.gen.jee.tests" non-regression plan is a good
point to guarantee stability and the module consistency. Indeed, it's good
tools but i think we could add a unit test suite to check all uses cases
defines by the non-regression plan. And, we could detect others problems like
my bug of the day 
Commentaires
Such long column names are bound to cause problems on Oracle, where the limit is 30 chars.
http://www.google.ca/search?q=oracl...
Maybe you should not be using the target table name in the name of the foreign key column.
The tests to check mapping validity is a good think. I'll try to create this kind on NR tests this year
Hi Rafael,
You're right, my sample can cause problems on Oracle. Maybe, we could add a properties use.short.fk.name=on or max.column.length=30 read by the PropertiesService in order to truncate the column's name. I think that we must not apply Oracle constraint for all supported databases.
If this feature can help you, you can add a feature request here : http://forge.objectweb.org/tracker/...
Cheers,
Jérôme.