Home » Modeling » EMF » [Teneo] Mapping a combined primary key with teneo
[Teneo] Mapping a combined primary key with teneo [message #1757860] |
Mon, 20 March 2017 19:43 |
Felix S Messages: 10 Registered: November 2014 |
Junior Member |
|
|
Hi,
I have a generated DB-Scheme, which I want to operate on with ecore and Teneo/Hibernate. To do so, I created a similar ecore model. This worked good so far. But now I encounter a problem with a table (DataValue in this case), which has a combined primary key of three columns (see DataValue_PK) and this table being referenced by another table (ValueConstraintValue) with this combined primary key (see ValueCsnrValue_FK2).
The part of interest of the scheme looks like this
CREATE TABLE DataType (
DataTypeID NVARCHAR2(128) NOT NULL,
CONSTRAINT DataT_PK PRIMARY KEY(DataTypeID),
-- skip some irrelevant stuff
);
CREATE TABLE DataValue (
DataTypeID NVARCHAR2(128) NOT NULL,
Value NVARCHAR2(512) NOT NULL,
LanguageCode NVARCHAR2(85) NOT NULL,
CONSTRAINT DataValue_PK PRIMARY KEY(DataTypeID, Value, LanguageCode),
CONSTRAINT DataValue_FK FOREIGN KEY (DataTypeID) REFERENCES DataType (DataTypeID)
);
CREATE TABLE ValueConstraintValue (
DataTypeID NVARCHAR2(128) NOT NULL,
Value NVARCHAR2(512) NOT NULL,
LanguageCode NVARCHAR2(85) NOT NULL,
ValueQID NVARCHAR2(128) NOT NULL,
CONSTRAINT ValueCsnrValue_PK PRIMARY KEY(DataTypeID, Value, LanguageCode, ValueQID),
CONSTRAINT ValueCsnrValue_FK1 FOREIGN KEY (ValueQID) REFERENCES ValueConstraint (ValueQID),
CONSTRAINT ValueCsnrValue_FK2 FOREIGN KEY (DataTypeID, Value, LanguageCode) REFERENCES DataValue (DataTypeID, Value, LanguageCode)
);
CREATE TABLE ValueConstraint (
ValueQID NVARCHAR2(128) NOT NULL,
CONSTRAINT ValueCsnr_PK PRIMARY KEY(ValueQID),
-- skip some more irrelevant stuff
);
Is there any chance, to reverse map this situation in ecore? I tried to annotate the DataValue-EClass with the Hibernate-Annotation @PrimaryKeyJoinColumns, but this didn't work.
As mentioned in the beginning, the scheme is generated by a tool, so I have few chances of altering the scheme, since it would affect other things in the scheme. So I hope, there is a solution for this problem.
Best regards
|
|
| |
Re: [Teneo] Mapping a combined primary key with teneo [message #1757892 is a reply to message #1757867] |
Tue, 21 March 2017 12:43 |
Felix S Messages: 10 Registered: November 2014 |
Junior Member |
|
|
Hi Martin,
thanks for the quick response
I implemented that ID-Class as suggested and annotated the DataValue-EClass as following
@IdClass(teneo.test.DataValueID)
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name="DataTypeID"),
@PrimaryKeyJoinColumn(name="Value"),
@PrimaryKeyJoinColumn(name="LanguageCode")
})
Regenerating and running this adjusted code gives me the following Exception:
java.lang.ExceptionInInitializerError
...
Caused by: org.hibernate.MappingException: Foreign key (valueconstraintvalue_datavalue:valueconstraintvalue [datatypeid,value,languagecode])) must have same number of columns as the referenced primary key (datavalue [e_id])
In the log I see also a message, saying that the PrimaryKeyJoinColumn-Annotation is ignored, since DataValue is a root in the class hierarchy.
Mär 21, 2017 11:47:17 AM org.eclipse.emf.teneo.hibernate.mapper.EntityMapper processEntity
WARNUNG: This entity (DataValue is the root in the class hierarchy and has a pk joincolum annotation, this is not correct, ignoring pk joincolumn annotation
I thought, that PrimaryKeyJoinColumns-Annotation is allowed for root class in an one-to-one-association, isn't it? Did I missed something?
Best regards
|
|
| | |
Goto Forum:
Current Time: Thu Mar 28 09:47:12 GMT 2024
Powered by FUDForum. Page generated in 0.04176 seconds
|