Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Not null constraint in JointTable when implementing Interface
[Teneo] Not null constraint in JointTable when implementing Interface [message #1009062] Thu, 14 February 2013 11:12 Go to next message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi,
I am looking for an annotation to solve the following mapping situation

PersistenceObject (interface)
Address
Addressable (interface)
Partner -> PersistenceObject, Addressable
Person -> PersistenceObject, Addressable

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="sample"
    nsURI="http://com.somesample" nsPrefix="sample">
  <eClassifiers xsi:type="ecore:EClass" name="PersistenceObject" abstract="true" interface="true">
    <eAnnotations source="teneo.jpa">
      <details key="appinfo" value="@MappedSuperclass"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELong"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Partner" eSuperTypes="#//PersistenceObject #//Addressable">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="partnerName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Person" eSuperTypes="#//PersistenceObject #//Addressable">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="personName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Address" eSuperTypes="#//PersistenceObject">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="address" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Addressable" abstract="true" interface="true">
    <eAnnotations source="teneo.jpa">
      <details key="appinfo" value="@MappedSuperclass"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EReference" name="adresses" ordered="false"
        upperBound="-1" eType="#//Address"/>
  </eClassifiers>
</ecore:EPackage>



with the respective mapping

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="false">
	<class name="sample.impl.PartnerImpl" entity-name="Partner" abstract="false" lazy="false" discriminator-value="Partner" table="`T_Partner`">
		<meta attribute="eclassName" inherit="false">Partner</meta>
		<meta attribute="epackage" inherit="false">http://com.somesample</meta>
		<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
			<meta attribute="syntheticId" inherit="false">true</meta>
			<generator class="native"/>
		</id>
		<discriminator type="string">
			<column name="`DTYPE`" index="T_PartnerDTYPE" length="255" not-null="true"/>
		</discriminator>
		<property name="id" lazy="false" insert="true" update="true" not-null="false" unique="false" type="long">
			<column not-null="false" unique="false" name="`id`"/>
		</property>
		<bag name="adresses" table="`JT_Addressable_adresses`" lazy="true" cascade="persist,merge,refresh,save-update,lock">
			<key update="true">
				<column name="`Partner_e_id`" unique="false" index="Addressable_adresses"/>
			</key>
			<many-to-many entity-name="Address" unique="true" foreign-key="FK_Partner_adresses">
				<column name="`Address_e_id`" unique="false" index="Addressable_adresses"/>
			</many-to-many>
		</bag>
		<property name="partnerName" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`partnerName`"/>
		</property>
	</class>
	<class name="sample.impl.PersonImpl" entity-name="Person" abstract="false" lazy="false" discriminator-value="Person" table="`T_Person`">
		<meta attribute="eclassName" inherit="false">Person</meta>
		<meta attribute="epackage" inherit="false">http://com.somesample</meta>
		<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
			<meta attribute="syntheticId" inherit="false">true</meta>
			<generator class="native"/>
		</id>
		<discriminator type="string">
			<column name="`DTYPE`" index="T_PersonDTYPE" length="255" not-null="true"/>
		</discriminator>
		<property name="id" lazy="false" insert="true" update="true" not-null="false" unique="false" type="long">
			<column not-null="false" unique="false" name="`id`"/>
		</property>
		<bag name="adresses" table="`JT_Addressable_adresses`" lazy="true" cascade="persist,merge,refresh,save-update,lock">
			<key update="true">
				<column name="`Person_e_id`" unique="false" index="Addressable_adresses"/>
			</key>
			<many-to-many entity-name="Address" unique="true" foreign-key="FK_Person_adresses">
				<column name="`Address_e_id`" unique="false" index="Addressable_adresses"/>
			</many-to-many>
		</bag>
		<property name="personName" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`personName`"/>
		</property>
	</class>
	<class name="sample.impl.AddressImpl" entity-name="Address" abstract="false" lazy="false" discriminator-value="Address" table="`T_Address`">
		<meta attribute="eclassName" inherit="false">Address</meta>
		<meta attribute="epackage" inherit="false">http://com.somesample</meta>
		<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
			<meta attribute="syntheticId" inherit="false">true</meta>
			<generator class="native"/>
		</id>
		<discriminator type="string">
			<column name="`DTYPE`" index="T_AddressDTYPE" length="255" not-null="true"/>
		</discriminator>
		<property name="id" lazy="false" insert="true" update="true" not-null="false" unique="false" type="long">
			<column not-null="false" unique="false" name="`id`"/>
		</property>
		<property name="address" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`address`"/>
		</property>
	</class>
</hibernate-mapping>



Now the joint table (JT_ADDRESSABLE_ADRESSES) that joins Addresses with Addressables has three foreign key columns: ADDRESS_E_ID, PARTNER_E_ID and PERSON_E_ID

Unfortunately all of them have a "NOT NULL" constraint.
Is there somebody who can tell me which annotations I have to use to solve this?

Thanks in advance
Thorsten
Solved: [Teneo] Not null constraint in JointTable when implementing Interface [message #1009283 is a reply to message #1009062] Thu, 14 February 2013 20:25 Go to previous message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
Just realized that this can be solved with a JPA annotation at Partner and Person class:

@AssociationOverride(
name="addresses",
joinTable=@JoinTable(
name="JT_PARTNER_ADDRESSES",
joinColumns=@JoinColumn(name="PARTNER_ID"),
inverseJoinColumns=@JoinColumn(name="ADDRESS_ID")
)
)

Which then results in two different JointTables.
Previous Topic:Duplicate content parser registration
Next Topic:[CDO] BufferUnderflowException when trying to connect with Java 7 (64bit)
Goto Forum:
  


Current Time: Sat Oct 25 01:39:09 GMT 2014

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

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