Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Reference common tables without regenerating(eCore to eCore reference deployed at different times)
[Teneo] Reference common tables without regenerating [message #1383938] Tue, 27 May 2014 10:01 Go to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

I'm investigating something that I'd really appreciate your input.

I have a "common" eCore (for simplicities sake, with a single table), I generate the schema for this eCore:

eCore:
  <eClassifiers xsi:type="ecore:EClass" name="Global1">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="Global1"/>
      <details key="kind" value="elementOnly"/>
    </eAnnotations>
    <eAnnotations source="bds">
      <details key="isGlobal" value="true"/>
    </eAnnotations>
    <eAnnotations source="teneo.jpa">
      <details key="value" value="@Table(name=&quot;SIMPLE_GLOBAL1&quot;)&#xA;@DiscriminatorValue(&quot;com.example.simple.Global1&quot;)"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="attribute1" eType="#//attribute1_Global1Type">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="attribute1"/>
      </eAnnotations>
      <eAnnotations source="bds">
        <details key="bomBaseType" value="Text"/>
      </eAnnotations>
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@Column(name=&quot;ATTRIBUTE1&quot;, length=&quot;400&quot;, nullable=&quot;true&quot;)"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject">
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@Id&#xA;@Column(name=&quot;BDS_ID&quot;, nullable=&quot;false&quot;)&#xA;@GeneratedValue(generator=&quot;bdsIdGenerator&quot;)"/>
      </eAnnotations>
      <eAnnotations source="bds">
        <details key="isId" value="true"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsOwnerId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject">
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@Column(name=&quot;BDS_OWNER_ID&quot;, nullable=&quot;true&quot;)"/>
      </eAnnotations>
      <eAnnotations source="bds">
        <details key="isCaseId" value="true"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>


Hibernate Mapping:
<hibernate-mapping auto-import="false">
	<class entity-name="Global1" abstract="false" lazy="false" discriminator-value="com.example.simple.Global1" table="`simple_global1`">
		<meta attribute="eclassName" inherit="false">Global1</meta>
		<meta attribute="epackage" inherit="false">http://example.com/simple</meta>
		<id name="bdsId" type="java.lang.Long">
			<column not-null="true" unique="false" name="`bds_id`"/>
			<generator class="native"/>
		</id>
		<discriminator type="string">
			<column name="`dtype`" index="SIMPLE_GLOBAL1dtype" length="255" not-null="true"/>
		</discriminator>
		<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
			<meta attribute="syntheticVersion" inherit="false">true</meta>
		</version>
		<property name="attribute1" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`attribute1`" length="400"/>
		</property>
		<property name="bdsOwnerId" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.Long">
			<column not-null="false" unique="false" name="`bds_owner_id`"/>
		</property>
	</class>
</hibernate-mapping>



Now I have another eCore that references that "already deployed and created eCore":

  <eClassifiers xsi:type="ecore:EClass" name="SecondGlobal1">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="SecondGlobal1"/>
      <details key="kind" value="elementOnly"/>
    </eAnnotations>
    <eAnnotations source="bds">
      <details key="isGlobal" value="true"/>
    </eAnnotations>
    <eAnnotations source="teneo.jpa">
      <details key="value" value="@Table(name=&quot;SECONDPROJ_SECONDGLOBAL1&quot;)&#xA;@DiscriminatorValue(&quot;com.example.secondproj.SecondGlobal1&quot;)"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EReference" name="attribute1" eType="ecore:EClass com.example.simple.bds.ecore#//Global1"
        containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="attribute1"/>
      </eAnnotations>
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@Column(name=&quot;ATTRIBUTE1&quot;, nullable=&quot;true&quot;)"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="attribute2" upperBound="-1"
        eType="ecore:EClass http://example.com/simple#//Global1" containment="true"
        resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="attribute2"/>
      </eAnnotations>
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@JoinTable(name=&quot;SECONDBOM_SECONDGLOBAL1_ATTRIBUTE2&quot;)&#xD;&#xA;@Column(name=&quot;ATTRIBUTE2&quot;, nullable=&quot;true&quot;)"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject">
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@Id&#xA;@Column(name=&quot;BDS_ID&quot;, nullable=&quot;false&quot;)&#xA;@GeneratedValue(generator=&quot;bdsIdGenerator&quot;)"/>
      </eAnnotations>
      <eAnnotations source="bds">
        <details key="isId" value="true"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsOwnerId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject">
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@Column(name=&quot;BDS_OWNER_ID&quot;, nullable=&quot;true&quot;)"/>
      </eAnnotations>
      <eAnnotations source="bds">
        <details key="isCaseId" value="true"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>



So I have an "ecore:EReference" pointing to the already deployed eCore.

If I do a normal generation of this extending eCore then I get an error:

Quote:
No annotated model element present for: Global1 for type EClass has its epackage been registered with Teneo?


So I then added:

props.setProperty(PersistenceOptions.AUTO_ADD_REFERENCED_EPACKAGES, "true");


Which will then generate the hibernate mapping:

<hibernate-mapping auto-import="false">
	<class entity-name="SecondGlobal1" abstract="false" lazy="false" discriminator-value="com.example.secondproj.SecondGlobal1" table="`secondproj_secondglobal1`">
		<meta attribute="eclassName" inherit="false">SecondGlobal1</meta>
		<meta attribute="epackage" inherit="false">http://example.com/secondproj</meta>
		<id name="bdsId" type="java.lang.Long">
			<column not-null="true" unique="false" name="`bds_id`"/>
			<generator class="native"/>
		</id>
		<discriminator type="string">
			<column name="`dtype`" index="SECONDPROJ_SECONDGLOBAL1dtype" length="255" not-null="true"/>
		</discriminator>
		<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
			<meta attribute="syntheticVersion" inherit="false">true</meta>
		</version>
		<many-to-one name="attribute1" entity-name="Global1" lazy="false" cascade="all" foreign-key="secondglobal1_attribute1" insert="true" update="true" not-null="false">
			<column not-null="false" unique="false" name="`global1_attribute1_bdsid`"/>
		</many-to-one>
		<list name="attribute2" table="`secondbom_secondglobal1_attribute2`" lazy="true" cascade="all,delete-orphan">
			<key foreign-key="secondglobal1_attribute2_key" update="true">
				<column name="`secondglobal1_bdsid`" unique="false"/>
			</key>
			<list-index column="`secondglobal1_attribute2_idx`"/>
			<many-to-many entity-name="Global1" unique="true" foreign-key="secondglobal1_attribute2">
				<column name="`global1_bdsid`" unique="false"/>
			</many-to-many>
		</list>
		<property name="bdsOwnerId" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.Long">
			<column not-null="false" unique="false" name="`bds_owner_id`"/>
		</property>
	</class>
	<class entity-name="Global1" abstract="false" lazy="false" discriminator-value="com.example.simple.Global1" table="`simple_global1`">
		<meta attribute="eclassName" inherit="false">Global1</meta>
		<meta attribute="epackage" inherit="false">http://example.com/simple</meta>
		<id name="bdsId" type="java.lang.Long">
			<column not-null="true" unique="false" name="`bds_id`"/>
			<generator class="native"/>
		</id>
		<discriminator type="string">
			<column name="`dtype`" index="SIMPLE_GLOBAL1dtype" length="255" not-null="true"/>
		</discriminator>
		<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
			<meta attribute="syntheticVersion" inherit="false">true</meta>
		</version>
		<property name="attribute1" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`attribute1`" length="400"/>
		</property>
		<property name="bdsOwnerId" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.Long">
			<column not-null="false" unique="false" name="`bds_owner_id`"/>
		</property>
	</class>
	<class entity-name="Global1" abstract="false" lazy="false" discriminator-value="com.example.simple.Global1" table="`simple_global1`">
		<meta attribute="eclassName" inherit="false">Global1</meta>
		<meta attribute="epackage" inherit="false">http://example.com/simple</meta>
		<id name="bdsId" type="java.lang.Long">
			<column not-null="true" unique="false" name="`bds_id`"/>
			<generator class="native"/>
		</id>
		<discriminator type="string">
			<column name="`dtype`" index="SIMPLE_GLOBAL1dtype" length="255" not-null="true"/>
		</discriminator>
		<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
			<meta attribute="syntheticVersion" inherit="false">true</meta>
		</version>
		<property name="attribute1" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`attribute1`" length="400"/>
		</property>
		<property name="bdsOwnerId" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.Long">
			<column not-null="false" unique="false" name="`bds_owner_id`"/>
		</property>
	</class>
</hibernate-mapping>


As it happens the Global1 appears to be pulled in twice? Giving the error:

Quote:
INFO: HHH000071: Duplicate import: Global1 -> Global1
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from string XML String
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3405)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3394)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3382)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1337)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1303)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildMappings(HbSessionDataStore.java:180)
at org.eclipse.emf.teneo.hibernate.HbDataStore.initializeDataStore(HbDataStore.java:356)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:116)
at teneotest.Linked.singleEcore(Linked.java:109)
at teneotest.Linked.runTest(Linked.java:38)
at teneotest.Linked.main(Linked.java:32)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping Global1



However, this is not my question! Smile

My question is:

How (is there a way?) do I correctly reference in EMF/Teneo another already deployed class/table so that it will not be regenerated in the database, and will instead use the existing table?

i.e. so the EReference is pointing to something that is already created? (And no attempt is made to create it again)

This could be the case where you have 1 common model and then many other models making use of it.

Thanks

Rob
P.S. I Have attached some of my very rough test code.
Re: [Teneo] Reference common tables without regenerating [message #1383950 is a reply to message #1383938] Tue, 27 May 2014 11:31 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi Rob,
My feel/idea is that there are 2 Global1 EPackages around somewhere, one is in the package registry and another one is
referenced from extending eclass/epackage. The datastore has a package registry which you can set, there is also the
PackageRegistryProvider being used in other cases.

Let me know if this hint helps or not.

btw, how do you do a normal generation? You mean initialization? What epackages do you set in the datastore?

gr. Martin

On 27-05-14 12:01, Rob Mising name wrote:
> Hi Martin,
>
> I'm investigating something that I'd really appreciate your input.
>
> I have a "common" eCore (for simplicities sake, with a single table), I generate the schema for this eCore:
>
> eCore:
> <eClassifiers xsi:type="ecore:EClass" name="Global1">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Global1"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isGlobal" value="true"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Table(name="SIMPLE_GLOBAL1")
> @DiscriminatorValue("com.example.simple.Global1")"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="attribute1" eType="#//attribute1_Global1Type">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="attribute1"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="bomBaseType" value="Text"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Column(name="ATTRIBUTE1", length="400", nullable="true")"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Id
> @Column(name="BDS_ID", nullable="false")
> @GeneratedValue(generator="bdsIdGenerator")"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isId" value="true"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsOwnerId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Column(name="BDS_OWNER_ID", nullable="true")"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isCaseId" value="true"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
>
> Hibernate Mapping:
> <hibernate-mapping auto-import="false">
> <class entity-name="Global1" abstract="false" lazy="false" discriminator-value="com.example.simple.Global1" table="`simple_global1`">
> <meta attribute="eclassName" inherit="false">Global1</meta>
> <meta attribute="epackage" inherit="false">http://example.com/simple</meta>
> <id name="bdsId" type="java.lang.Long">
> <column not-null="true" unique="false" name="`bds_id`"/>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="`dtype`" index="SIMPLE_GLOBAL1dtype" length="255" not-null="true"/>
> </discriminator>
> <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
> <meta attribute="syntheticVersion" inherit="false">true</meta>
> </version>
> <property name="attribute1" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`attribute1`" length="400"/>
> </property>
> <property name="bdsOwnerId" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.Long">
> <column not-null="false" unique="false" name="`bds_owner_id`"/>
> </property>
> </class>
> </hibernate-mapping>
>
>
> Now I have another eCore that references that "already deployed and created eCore":
>
> <eClassifiers xsi:type="ecore:EClass" name="SecondGlobal1">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="SecondGlobal1"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isGlobal" value="true"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Table(name="SECONDPROJ_SECONDGLOBAL1")
> @DiscriminatorValue("com.example.secondproj.SecondGlobal1")"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EReference" name="attribute1" eType="ecore:EClass com.example.simple.bds.ecore#//Global1"
> containment="true" resolveProxies="false">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="attribute1"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Column(name="ATTRIBUTE1", nullable="true")"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="attribute2" upperBound="-1"
> eType="ecore:EClass http://example.com/simple#//Global1" containment="true"
> resolveProxies="false">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="attribute2"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@JoinTable(name="SECONDBOM_SECONDGLOBAL1_ATTRIBUTE2")
> @Column(name="ATTRIBUTE2", nullable="true")"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Id
> @Column(name="BDS_ID", nullable="false")
> @GeneratedValue(generator="bdsIdGenerator")"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isId" value="true"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsOwnerId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Column(name="BDS_OWNER_ID", nullable="true")"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isCaseId" value="true"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
>
>
> So I have an "ecore:EReference" pointing to the already deployed eCore.
>
> If I do a normal generation of this extending eCore then I get an error:
>
> Quote:
>> No annotated model element present for: Global1 for type EClass has its epackage been registered with Teneo?
>
>
> So I then added:
>
> props.setProperty(PersistenceOptions.AUTO_ADD_REFERENCED_EPACKAGES, "true");
>
> Which will then generate the hibernate mapping:
>
> <hibernate-mapping auto-import="false">
> <class entity-name="SecondGlobal1" abstract="false" lazy="false" discriminator-value="com.example.secondproj.SecondGlobal1" table="`secondproj_secondglobal1`">
> <meta attribute="eclassName" inherit="false">SecondGlobal1</meta>
> <meta attribute="epackage" inherit="false">http://example.com/secondproj</meta>
> <id name="bdsId" type="java.lang.Long">
> <column not-null="true" unique="false" name="`bds_id`"/>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="`dtype`" index="SECONDPROJ_SECONDGLOBAL1dtype" length="255" not-null="true"/>
> </discriminator>
> <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
> <meta attribute="syntheticVersion" inherit="false">true</meta>
> </version>
> <many-to-one name="attribute1" entity-name="Global1" lazy="false" cascade="all" foreign-key="secondglobal1_attribute1" insert="true" update="true" not-null="false">
> <column not-null="false" unique="false" name="`global1_attribute1_bdsid`"/>
> </many-to-one>
> <list name="attribute2" table="`secondbom_secondglobal1_attribute2`" lazy="true" cascade="all,delete-orphan">
> <key foreign-key="secondglobal1_attribute2_key" update="true">
> <column name="`secondglobal1_bdsid`" unique="false"/>
> </key>
> <list-index column="`secondglobal1_attribute2_idx`"/>
> <many-to-many entity-name="Global1" unique="true" foreign-key="secondglobal1_attribute2">
> <column name="`global1_bdsid`" unique="false"/>
> </many-to-many>
> </list>
> <property name="bdsOwnerId" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.Long">
> <column not-null="false" unique="false" name="`bds_owner_id`"/>
> </property>
> </class>
> <class entity-name="Global1" abstract="false" lazy="false" discriminator-value="com.example.simple.Global1" table="`simple_global1`">
> <meta attribute="eclassName" inherit="false">Global1</meta>
> <meta attribute="epackage" inherit="false">http://example.com/simple</meta>
> <id name="bdsId" type="java.lang.Long">
> <column not-null="true" unique="false" name="`bds_id`"/>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="`dtype`" index="SIMPLE_GLOBAL1dtype" length="255" not-null="true"/>
> </discriminator>
> <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
> <meta attribute="syntheticVersion" inherit="false">true</meta>
> </version>
> <property name="attribute1" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`attribute1`" length="400"/>
> </property>
> <property name="bdsOwnerId" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.Long">
> <column not-null="false" unique="false" name="`bds_owner_id`"/>
> </property>
> </class>
> <class entity-name="Global1" abstract="false" lazy="false" discriminator-value="com.example.simple.Global1" table="`simple_global1`">
> <meta attribute="eclassName" inherit="false">Global1</meta>
> <meta attribute="epackage" inherit="false">http://example.com/simple</meta>
> <id name="bdsId" type="java.lang.Long">
> <column not-null="true" unique="false" name="`bds_id`"/>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="`dtype`" index="SIMPLE_GLOBAL1dtype" length="255" not-null="true"/>
> </discriminator>
> <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
> <meta attribute="syntheticVersion" inherit="false">true</meta>
> </version>
> <property name="attribute1" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`attribute1`" length="400"/>
> </property>
> <property name="bdsOwnerId" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.Long">
> <column not-null="false" unique="false" name="`bds_owner_id`"/>
> </property>
> </class>
> </hibernate-mapping>
>
> As it happens the Global1 appears to be pulled in twice? Giving the error:
>
> Quote:
>> INFO: HHH000071: Duplicate import: Global1 -> Global1
>> Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from string XML String
>> at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3405)
>> at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3394)
>> at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3382)
>> at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1337)
>> at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1303)
>> at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildMappings(HbSessionDataStore.java:180)
>> at org.eclipse.emf.teneo.hibernate.HbDataStore.initializeDataStore(HbDataStore.java:356)
>> at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:116)
>> at teneotest.Linked.singleEcore(Linked.java:109)
>> at teneotest.Linked.runTest(Linked.java:38)
>> at teneotest.Linked.main(Linked.java:32)
>> Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping Global1
>
>
>
> However, this is not my question! :)
>
> My question is:
>
> How (is there a way?) do I correctly reference in EMF/Teneo another already deployed class/table so that it will not be regenerated in the database, and will instead use the existing table?
>
> i.e. so the EReference is pointing to something that is already created? (And no attempt is made to create it again)
>
> This could be the case where you have 1 common model and then many other models making use of it.
>
> Thanks
>
> Rob
> P.S. I Have attached some of my very rough test code.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] Reference common tables without regenerating [message #1383960 is a reply to message #1383950] Tue, 27 May 2014 13:06 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

Thank you for your reply. I have attached my test program to the first post (it's only a handful of lines long - just in case it clarifies my ramblings).

I'm not too worried about the duplicate Global1 in the hibernate mapping. I'm more wondering about the following:

Quote:
How (is there a way?) do I correctly reference in EMF/Teneo another already deployed class/table so that it will not be regenerated in the database, and will instead use the existing table?


I would be very interested in hearing your thoughts with insight to this being possible or not?

Thanks

Rob
Re: [Teneo] Reference common tables without regenerating [message #1384001 is a reply to message #1383960] Tue, 27 May 2014 19:18 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hey Rob
Ouch I missed the attachments :-), now I looked at them.

With this code Teneo and EMF will use the global package registry EPackage.Registry. I think that's fine.

However, I checked the secondproj ecore and there I can find 2 ways of referencing Global1, the first reference uses a
file uri, the second one the nsuri. I think this will result in EMF loading the simple ecore again (to resolve the first
reference). So as long as you first load the global ecore and all the references use the nsuri then there should only be
on instance of Global1 in the package registry/memory.

<StructuralFeatures xsi:type="ecore:EReference" name="attribute1" eType="ecore:EClass
com.example.simple.bds.ecore#//Global1" containment="true" resolveProxies="false">

<eStructuralFeatures xsi:type="ecore:EReference" name="attribute2" upperBound="-1" eType="ecore:EClass
http://example.com/simple#//Global1" containment="true"

To answer your question, Teneo/Hibernate always needs a complete picture of the database and tables. So therefore it
needs to have all the mappings available. This is done by adding all the epackages to the datastore. The mapping of the
global models is done the same as if the global epackages were set in their own datastore, this means that existing
tables will be re-used.

gr. Martin


On 27-05-14 15:06, Rob Mising name wrote:
> Hi Martin,
>
> Thank you for your reply. I have attached my test program to the first post (it's only a handful of lines long - just
> in case it clarifies my ramblings).
>
> I'm not too worried about the duplicate Global1 in the hibernate mapping. I'm more wondering about the following:
>
> Quote:
>> How (is there a way?) do I correctly reference in EMF/Teneo another already deployed class/table so that it will not
>> be regenerated in the database, and will instead use the existing table?
>
>
> I would be very interested in hearing your thoughts with insight to this being possible or not?
>
> Thanks
>
> Rob
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] Reference common tables without regenerating [message #1384159 is a reply to message #1384001] Wed, 28 May 2014 09:30 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

Thankyou for taking the time to look at that - good spot with the different references in the eCore!

I have been looking at the output for the database generation when using:

config.generateSchemaCreationScript(dialect);


After generating from com.example.simple.bds.ecore I get the create script as follows:

create table [simple_global1] ([bds_id] bigint identity not null, [dtype] varchar(255) not null, e_version int not null, [attribute1] varchar(400), [bds_owner_id] bigint, primary key ([bds_id]))
create index SIMPLE_GLOBAL1dtype on [simple_global1] ([dtype])


Now if I generate the create script from com.example.secondproj.bds.ecore I get:

create table [secondbom_secondglobal1_attribute2] ([secondglobal1_bdsid] bigint not null, [global1_bdsid] bigint not null, [secondglobal1_attribute2_idx] int not null, primary key ([secondglobal1_bdsid], [secondglobal1_attribute2_idx]))
create table [secondproj_secondglobal1] ([bds_id] bigint identity not null, [dtype] varchar(255) not null, e_version int not null, [global1_attribute1_bdsid] bigint, [bds_owner_id] bigint, primary key ([bds_id]))
create table [simple_global1] ([bds_id] bigint identity not null, [dtype] varchar(255) not null, e_version int not null, [attribute1] varchar(400), [bds_owner_id] bigint, primary key ([bds_id]))
alter table [secondbom_secondglobal1_attribute2] add constraint secondglobal1_attribute2 foreign key ([global1_bdsid]) references [simple_global1]
alter table [secondbom_secondglobal1_attribute2] add constraint secondglobal1_attribute2_key foreign key ([secondglobal1_bdsid]) references [secondproj_secondglobal1]
create index SECONDPROJ_SECONDGLOBAL1dtype on [secondproj_secondglobal1] ([dtype])
alter table [secondproj_secondglobal1] add constraint secondglobal1_attribute1 foreign key ([global1_attribute1_bdsid]) references [simple_global1]
create index SIMPLE_GLOBAL1dtype on [simple_global1] ([dtype])


So the table for Global1 [simple_global1] has been created by this script as well (Even though it already existed as it was created by the previous eCore - com.example.simple.bds.ecore).

Is there any way (maybe an annotation or something) that I can stop this duplicate create table (and index) command being generated?

Thank you again!

Rob
Re: [Teneo] Reference common tables without regenerating [message #1384588 is a reply to message #1384159] Thu, 29 May 2014 12:01 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi Rob,
You can tell hibernate to update the schema by setting the hibernate.hbm2ddl.auto property to 'update'. Or you can
call/use the SchemaUpdate class directly.

See also here:
http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html_single/#toolsetguide-s1-6

But I remember that the schema update had some limitations, indexes were not added, columns are not removed. But you can
try it.

An interesting tool to check out is liquibase: http://www.liquibase.org/

gr. Martin


On 28-05-14 11:30, Rob Mising name wrote:
> Hi Martin,
>
> Thankyou for taking the time to look at that - good spot with the different references in the eCore!
>
> I have been looking at the output for the database generation when using:
>
> config.generateSchemaCreationScript(dialect);
>
> After generating from com.example.simple.bds.ecore I get the create script as follows:
>
> create table [simple_global1] ([bds_id] bigint identity not null, [dtype] varchar(255) not null, e_version int not null,
> [attribute1] varchar(400), [bds_owner_id] bigint, primary key ([bds_id]))
> create index SIMPLE_GLOBAL1dtype on [simple_global1] ([dtype])
>
>
> Now if I generate the create script from com.example.secondproj.bds.ecore I get:
>
> create table [secondbom_secondglobal1_attribute2] ([secondglobal1_bdsid] bigint not null, [global1_bdsid] bigint not
> null, [secondglobal1_attribute2_idx] int not null, primary key ([secondglobal1_bdsid], [secondglobal1_attribute2_idx]))
> create table [secondproj_secondglobal1] ([bds_id] bigint identity not null, [dtype] varchar(255) not null, e_version int
> not null, [global1_attribute1_bdsid] bigint, [bds_owner_id] bigint, primary key ([bds_id]))
> create table [simple_global1] ([bds_id] bigint identity not null, [dtype] varchar(255) not null, e_version int not null,
> [attribute1] varchar(400), [bds_owner_id] bigint, primary key ([bds_id]))
> alter table [secondbom_secondglobal1_attribute2] add constraint secondglobal1_attribute2 foreign key ([global1_bdsid])
> references [simple_global1]
> alter table [secondbom_secondglobal1_attribute2] add constraint secondglobal1_attribute2_key foreign key
> ([secondglobal1_bdsid]) references [secondproj_secondglobal1]
> create index SECONDPROJ_SECONDGLOBAL1dtype on [secondproj_secondglobal1] ([dtype])
> alter table [secondproj_secondglobal1] add constraint secondglobal1_attribute1 foreign key ([global1_attribute1_bdsid])
> references [simple_global1]
> create index SIMPLE_GLOBAL1dtype on [simple_global1] ([dtype])
>
>
> So the table for Global1 [simple_global1] has been created by this script as well (Even though it already existed as it
> was created by the previous eCore - com.example.simple.bds.ecore).
>
> Is there any way (maybe an annotation or something) that I can stop this duplicate create table (and index) command
> being generated?
>
> Thank you again!
>
> Rob
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:[CDO] CDO Server in daemon mode with start, stop restart
Next Topic:[CDO] Something goes wrong with the repo to corrupt it
Goto Forum:
  


Current Time: Thu Dec 18 04:17:35 GMT 2014

Powered by FUDForum. Page generated in 0.07124 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software