| [Teneo] OneToOne turns into ManyToOne [message #936177] |
Sun, 07 October 2012 15:30  |
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   |
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02371 seconds