Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] OneToOne turns into ManyToOne
[Teneo] OneToOne turns into ManyToOne [message #936177] Sun, 07 October 2012 15:30 Go to next message
Nikita Missing name
Messages: 32
Registered: October 2009
Member
Hello,

I am trying to map this XSD with a OneToOne relationship:
  <xsd:complexType name="EmployeeWithSecurityCard">
    <xsd:sequence>
      <xsd:element name="id" type="xsd:int">
        <xsd:annotation><xsd:appinfo source="teneo.jpa">@Id @GeneratedValue</xsd:appinfo></xsd:annotation>
      </xsd:element>
      <xsd:element name="firstName" type="xsd:string" />
      <xsd:element name="lastName" type="xsd:string" />
      <xsd:element name="securityCard" type="SecurityAccessCard" minOccurs="0" maxOccurs="1">
        <xsd:annotation><xsd:appinfo source="teneo.jpa">
          @OneToOne @JoinColumn(name="security_card", unique=true)
        </xsd:appinfo></xsd:annotation>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="SecurityAccessCard">
    <xsd:sequence>
      <xsd:element name="accessCode" type="xsd:string" />
      <xsd:element name="expirationDate" type="xsd:dateTime" />
      <xsd:element name="id" type="xsd:int">
        <xsd:annotation><xsd:appinfo source="teneo.jpa">@Id @GeneratedValue</xsd:appinfo></xsd:annotation>
      </xsd:element>
      <xsd:element name="employee" type="EmployeeWithSecurityCard" ecore:opposite="securityCard" minOccurs="0" maxOccurs="1">
        <xsd:annotation><xsd:appinfo source="teneo.jpa">
          @OneToOne(mappedBy="securityCard")
        </xsd:appinfo></xsd:annotation>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>


This results in the following Hibernate XML:
  <class entity-name="EmployeeWithSecurityCardDT3231" abstract="false" lazy="false" table="`employeewithsecuritycard`">
    <meta attribute="eclassName" inherit="false">EmployeeWithSecurityCardDT3231</meta>
    <meta attribute="epackage" inherit="false">urn:teneo:test:EntityMappingsProviderTest</meta>
    <id name="id" type="int" unsaved-value="0">
      <column not-null="true" unique="false" name="`id`"/>
      <generator class="native"/>
    </id>
    <property name="firstName" lazy="false" insert="true" update="true" not-null="true" unique="false" type="java.lang.String">
      <column not-null="true" unique="false" name="`firstname`"/>
    </property>
    <property name="lastName" lazy="false" insert="true" update="true" not-null="true" unique="false" type="java.lang.String">
      <column not-null="true" unique="false" name="`lastname`"/>
    </property>
    <many-to-one name="securityCard" entity-name="SecurityAccessCardDT3247" cascade="all" not-null="false" lazy="false" insert="true" update="true">
      <column not-null="false" unique="true" name="`security_card`"/>
    </many-to-one>
  </class>

  <class entity-name="SecurityAccessCardDT3247" abstract="false" lazy="false" table="`securityaccesscard`">
    <meta attribute="eclassName" inherit="false">SecurityAccessCardDT3247</meta>
    <meta attribute="epackage" inherit="false">urn:teneo:test:EntityMappingsProviderTest</meta>
    <id name="id" type="int" unsaved-value="0">
      <column not-null="true" unique="false" name="`id`"/>
      <generator class="native"/>
    </id>
    <property name="accessCode" lazy="false" insert="true" update="true" not-null="true" unique="false" type="java.lang.String">
      <column not-null="true" unique="false" name="`accesscode`"/>
    </property>
    <property name="expirationDate" lazy="false" insert="true" update="true" not-null="true" unique="false" type="org.eclipse.emf.teneo.hibernate.mapping.XSDDateTime">
      <column not-null="true" unique="false" name="`expirationdate`"/>
    </property>
    <one-to-one name="employee" entity-name="EmployeeWithSecurityCardDT3231" cascade="all" lazy="false" property-ref="securityCard"/>
  </class>


On the Employee entity, the relationship is created as ManyToOne, rather than OneToOne. Is there something that I'm missing to make this a OneToOne on both sides?

Thank you,
Nikita
Re: [Teneo] OneToOne turns into ManyToOne [message #936224 is a reply to message #936177] Sun, 07 October 2012 16:40 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5054
Registered: July 2009
Senior Member
Hi Nikita,
Teneo follows this example for bi-directional one-to-one on a foreign key:
http://docs.jboss.org/hibernate/core/4.1/manual/en-US/html_single/#assoc-bidirectional-121

If the association was on the primary key then you would have a one-to-one on both sides.

So it is by design.

gr. Martin


On 10/07/2012 09:30 PM, Nikita Mising name wrote:
> Hello,
>
> I am trying to map this XSD with a OneToOne relationship:
>
> <xsd:complexType name="EmployeeWithSecurityCard">
> <xsd:sequence>
> <xsd:element name="id" type="xsd:int">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">@Id @GeneratedValue</xsd:appinfo></xsd:annotation>
> </xsd:element>
> <xsd:element name="firstName" type="xsd:string" />
> <xsd:element name="lastName" type="xsd:string" />
> <xsd:element name="securityCard" type="SecurityAccessCard" minOccurs="0" maxOccurs="1">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @OneToOne @JoinColumn(name="security_card", unique=true)
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="SecurityAccessCard">
> <xsd:sequence>
> <xsd:element name="accessCode" type="xsd:string" />
> <xsd:element name="expirationDate" type="xsd:dateTime" />
> <xsd:element name="id" type="xsd:int">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">@Id @GeneratedValue</xsd:appinfo></xsd:annotation>
> </xsd:element>
> <xsd:element name="employee" type="EmployeeWithSecurityCard" ecore:opposite="securityCard" minOccurs="0"
> maxOccurs="1">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @OneToOne(mappedBy="securityCard")
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
>
>
> This results in the following Hibernate XML:
>
> <class entity-name="EmployeeWithSecurityCardDT3231" abstract="false" lazy="false" table="`employeewithsecuritycard`">
> <meta attribute="eclassName" inherit="false">EmployeeWithSecurityCardDT3231</meta>
> <meta attribute="epackage" inherit="false">urn:teneo:test:EntityMappingsProviderTest</meta>
> <id name="id" type="int" unsaved-value="0">
> <column not-null="true" unique="false" name="`id`"/>
> <generator class="native"/>
> </id>
> <property name="firstName" lazy="false" insert="true" update="true" not-null="true" unique="false"
> type="java.lang.String">
> <column not-null="true" unique="false" name="`firstname`"/>
> </property>
> <property name="lastName" lazy="false" insert="true" update="true" not-null="true" unique="false"
> type="java.lang.String">
> <column not-null="true" unique="false" name="`lastname`"/>
> </property>
> <many-to-one name="securityCard" entity-name="SecurityAccessCardDT3247" cascade="all" not-null="false" lazy="false"
> insert="true" update="true">
> <column not-null="false" unique="true" name="`security_card`"/>
> </many-to-one>
> </class>
>
> <class entity-name="SecurityAccessCardDT3247" abstract="false" lazy="false" table="`securityaccesscard`">
> <meta attribute="eclassName" inherit="false">SecurityAccessCardDT3247</meta>
> <meta attribute="epackage" inherit="false">urn:teneo:test:EntityMappingsProviderTest</meta>
> <id name="id" type="int" unsaved-value="0">
> <column not-null="true" unique="false" name="`id`"/>
> <generator class="native"/>
> </id>
> <property name="accessCode" lazy="false" insert="true" update="true" not-null="true" unique="false"
> type="java.lang.String">
> <column not-null="true" unique="false" name="`accesscode`"/>
> </property>
> <property name="expirationDate" lazy="false" insert="true" update="true" not-null="true" unique="false"
> type="org.eclipse.emf.teneo.hibernate.mapping.XSDDateTime">
> <column not-null="true" unique="false" name="`expirationdate`"/>
> </property>
> <one-to-one name="employee" entity-name="EmployeeWithSecurityCardDT3231" cascade="all" lazy="false"
> property-ref="securityCard"/>
> </class>
>
>
> On the Employee entity, the relationship is created as ManyToOne, rather than OneToOne. Is there something that I'm
> missing to make this a OneToOne on both sides?
>
> Thank you,
> Nikita


--

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] OneToOne turns into ManyToOne [message #944609 is a reply to message #936224] Sun, 14 October 2012 23:13 Go to previous message
Nikita Missing name
Messages: 32
Registered: October 2009
Member
Ah, I understand. Thanks Martin!

Nikita
Previous Topic:hashcode and Map (non mutable case)
Next Topic:EMF Proxy
Goto Forum:
  


Current Time: Fri May 24 07:50:18 EDT 2013

Powered by FUDForum. Page generated in 0.02371 seconds