[Teneo] Problem setting a primary composite key that is also a foreign key [message #1720132] |
Thu, 14 January 2016 10:45  |
Eclipse User |
|
|
|
Hi,
i am currently trying to reverse engineer an existing database structure into an Ecore model with Teneo. I created an Ecore model that closely resembles the model of the existing database structure with Xcore. Now i am using Teneo to configure the relational mapping.
One eclass has a composite primary key consisting of a primitive String value and a foreign key. I am having trouble configuring Teneo to resemble that behavior.
The Xcore file
class Attribute {
contains AttributeConstraint[] Constraints opposite Attribute
}
class AttributeConstraint {
container Attribute Attribute opposite TaggedValues
String Value
}
I must configure Teneo via an annotations.xml file, because the Ecore model is still being altered.
The annotations.xml file
<eclass name="AttributeConstraint">
<id-class>de.cooperateproject.eabridge.eaobjectmodel.custom.AttributeConstraintPK</id-class>
<table name="t_attributeconstraints"/>
<property name="Attribute">
<id/>
<many-to-one></many-to-one>
<join-column name="ID"/>
</property>
<property name="Constraint">
<id/>
</property>
The id-class file
public class AttributeConstraintPK implements Serializable {
private static final long serialVersionUID = 6403908284592273608L;
protected String Constraint;
protected Long Attribute;
public AttributeConstraintPK(String constraint, Long attribute) {
super();
Constraint = constraint;
Attribute = attribute;
}
public AttributeConstraintPK() {
super();
// TODO Auto-generated constructor stub
}
// hashcode, equals, getter & setter
}
With this setup the <id/> annotation for the foreign key keeps getting ignored. I had success manually writing the hibernate.hbm.xml file, but that is not a good solution imho.
Also is there a reference sheet for the xml scheme of Teneo? I tried configuring it like the hibernate xml schema and had no success. After some hours of trying i understood that it is somewhat similiar to the hibernate Java annotation syntax. Is that assumption true?
|
|
|
|
|
|
|
|
|
Re: [Teneo] Problem setting a primary composite key that is also a foreign key [message #1735520 is a reply to message #1720132] |
Mon, 20 June 2016 10:27  |
Eclipse User |
|
|
|
We did some experiments in the meantime but we only got the mapping working by manually maintaining the attribute reference and using the Hibernate mapping XML generated for the previous case that includes the opposite reference. This seems to work without the endless loop. Anyway, this solution is not good:
- The model can become inconsistent because there is no relation between the containment reference and the opposite reference anymore.
- We had to switch from the generated hibernate mapping XML to a manually maintained one to keep the mapping working (cf. the code snippets below).
Wrong:
<bag name="TheChildren" lazy="true" cascade="all,delete-orphan">
<key foreign-key="ClassA_TheChildren_key" update="true">
<column name="`ClassA_TheChildren_ID`" unique="false"/>
</key>
<one-to-many entity-name="ClassB"/>
</bag> Correct:
<bag name="TheChildren" lazy="true" cascade="all,delete-orphan">
<key update="true">
<column name="`ParentID`" unique="false"/>
</key>
<one-to-many entity-name="ClassB"/>
</bag>
I would be grateful for every hint on how to handle these shortcomings.
|
|
|
Powered by
FUDForum. Page generated in 0.24471 seconds