|
Re: [Teneo] Semantics of Hibernate Bag for a non indexed many-to-many association [message #1033647 is a reply to message #1033567] |
Thu, 04 April 2013 13:29 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Josh,
Set is not possible and I think it results in the same issue. But you can try idbag to see if that helps. There is an
IdBag annotation or you can set it globally, see the idbag related options here:
http://wiki.eclipse.org/Teneo/Hibernate/Configuration_Options
gr. Martin
On 04/04/2013 01:28 PM, Josh A wrote:
> I have a non indexed many-to-many association(@ManyToMany(indexed=false)) in my model.
>
> I have an 'Order' EClass contains an attribute named 'orderTakers' defined as following
>
>
> <eStructuralFeatures xsi:type="ecore:EReference" name="orderTakers" upperBound="-1"
> eType="#/0/Employee" eOpposite="#/0/Employee/ordersTaken">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="orderTakers"/>
> </eAnnotations>
> </eStructuralFeatures>
>
>
> 'Employee' EClass contains an attribute named 'ordersTaken' defined as following
>
>
> <eStructuralFeatures xsi:type="ecore:EReference" name="ordersTaken" upperBound="-1"
> eType="#/0/Order" eOpposite="#/0/Order/orderTakers">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="ordersTaken"/>
> </eAnnotations>
> </eStructuralFeatures>
>
>
>
> I then inserted @ManyToMany(indexed=false) at both ends of the association. This resulted in the following mapping XML
> snippet.
>
>
> <bag name="orderTakers" lazy="true" table="CM_XMPL_RDRMDL_MPLYE_RDERSTKEN">
> <key update="true">
> <column name="ORDER_BDSID" not-null="true" unique="false"/>
> </key>
> <many-to-many entity-name="com.example.ordermodel.Employee" unique="false">
> <column name="EMPLOYEE_BDSID" not-null="true" unique="false"/>
> </many-to-many>
> </bag>
>
> <bag name="ordersTaken" lazy="true" inverse="true" table="CM_XMPL_RDRMDL_MPLYE_RDERSTKEN">
> <key update="true">
> <column name="EMPLOYEE_BDSID" not-null="true" unique="false"/>
> </key>
> <many-to-many entity-name="com.example.ordermodel.Order" unique="false">
> <column name="ORDER_BDSID" not-null="true" unique="false"/>
> </many-to-many>
> </bag>
>
>
> I created an Order,4 employees and created the link/association such that an Order has 4 employees as order takers.I
> then tried to unlink 1 employee from the association so that there are only 3 employees as the ordertakers for this Order.
>
> However, as described in http://assarconsulting.blogspot.co.uk/2009/08/why-hibernate-does-delete-all-then-re.html, i am
> finding that Hibernate is removing all employees first and re-inserting 3.
>
> Is mapping to Set(rather than bag) the solution to this problem? If so, how do i achieve this via Teneo JPA Annotations?
--
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] Semantics of Hibernate Bag for a non indexed many-to-many association [message #1036655 is a reply to message #1033647] |
Mon, 08 April 2013 17:03 |
Josh A Messages: 13 Registered: September 2012 |
Junior Member |
|
|
Hi,
I wonder whether i have hit a slight roadblock with IdBag usage. For the many-to-many example, in my previous mail, i have inserted the following annotations on respective sides of associations.
@ManyToMany(indexed=false)
@IdBag(table="ORDERMODEL_ORDER_ORDERTAKERS")
@ManyToMany(mappedBy="orderTakers",indexed=false)
@IdBag(table="ORDERMODEL_ORDER_ORDERTAKERS")
This results in the following mapping XML.
<idbag name="ordersTaken" lazy="true" table="CM_XMPL_RDRMDL_MPLYE_RDERSTKEN">
<collection-id column="ID" type="long">
<generator class="increment"/>
</collection-id>
<key update="true">
<column name="EMPLOYEE_ID" not-null="true" unique="false"/>
</key>
<many-to-many entity-name="com.example.ordermodel.Order" unique="false">
<column name="ORDER_ID" not-null="true" unique="false"/>
</many-to-many>
</idbag>
<idbag name="orderTakers" lazy="true" table="CM_XMPL_RDRMDL_MPLYE_RDERSTKEN">
<collection-id column="ID" type="long">
<generator class="increment"/>
</collection-id>
<key update="true">
<column name="ORDER_ID" not-null="true" unique="false"/>
</key>
<many-to-many entity-name="com.example.ordermodel.Employee" unique="false">
<column name="EMPLOYEE_ID" not-null="true" unique="false"/>
</many-to-many>
</idbag>
I created an Order,4 employees and then tried to create the link/association such that an Order has 3 employees as orderTakers.However, this failed with a Primary Key violation exception from CM_XMPL_RDRMDL_MPLYE_RDERSTKEN table since Hibernate is trying to insert 6 rows(3 of the rows are duplicates) in CM_XMPL_RDRMDL_MPLYE_RDERSTKEN in table.
I was interested to see if an inverse="true" on one of the idbags could inflence this problem. However, if i am not mistaken, it appears that the mapping DTD in the version(3.2.7) of the hibernate i use do not have an 'inverse' attribute for idBag element.Perhaps, this was introduced in later versions of hibernate.
Is there any way to resolve this?
Thanks,
Josh
|
|
|
Re: [Teneo] Semantics of Hibernate Bag for a non indexed many-to-many association [message #1038032 is a reply to message #1036655] |
Wed, 10 April 2013 10:06 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Josh,
Seems to be this case:
http://suneelgv.wordpress.com/2008/11/22/hibernate-why-do-we-use-inversetrue-in-many-to-many/
To be sure, in the model did you set the eopposite of the associations?
If so then this seems to be a bug, inverse=true should have been set. In that case can you enter a bugzilla? Just refer
to this discussion using a link.
gr. Martin
On 04/08/2013 07:03 PM, Josh A wrote:
> Hi,
>
> I wonder whether i have hit a slight roadblock with IdBag usage. For the many-to-many example, in my previous mail, i
> have inserted the following annotations on respective sides of associations.
>
>
> @ManyToMany(indexed=false)
> @IdBag(table="ORDERMODEL_ORDER_ORDERTAKERS")
>
>
>
> @ManyToMany(mappedBy="orderTakers",indexed=false)
> @IdBag(table="ORDERMODEL_ORDER_ORDERTAKERS")
>
>
> This results in the following mapping XML.
>
>
> <idbag name="ordersTaken" lazy="true" table="CM_XMPL_RDRMDL_MPLYE_RDERSTKEN">
> <collection-id column="ID" type="long">
> <generator class="increment"/>
> </collection-id>
> <key update="true">
> <column name="EMPLOYEE_ID" not-null="true" unique="false"/>
> </key>
> <many-to-many entity-name="com.example.ordermodel.Order" unique="false">
> <column name="ORDER_ID" not-null="true" unique="false"/>
> </many-to-many>
> </idbag>
>
>
>
>
> <idbag name="orderTakers" lazy="true" table="CM_XMPL_RDRMDL_MPLYE_RDERSTKEN">
> <collection-id column="ID" type="long">
> <generator class="increment"/>
> </collection-id>
> <key update="true">
> <column name="ORDER_ID" not-null="true" unique="false"/>
> </key>
> <many-to-many entity-name="com.example.ordermodel.Employee" unique="false">
> <column name="EMPLOYEE_ID" not-null="true" unique="false"/>
> </many-to-many>
> </idbag>
>
>
> I created an Order,4 employees and then tried to create the link/association such that an Order has 3 employees as
> orderTakers.However, this failed with a Primary Key violation exception from CM_XMPL_RDRMDL_MPLYE_RDERSTKEN table since
> Hibernate is trying to insert 6 rows(3 of the rows are duplicates) in CM_XMPL_RDRMDL_MPLYE_RDERSTKEN in table.
>
> I was interested to see if an inverse="true" on one of the idbags could inflence this problem. However, if i am not
> mistaken, it appears that the mapping DTD in the version(3.2.7) of the hibernate i use do not have an 'inverse'
> attribute for idBag element.Perhaps, this was introduced in later versions of hibernate.
>
> Is there any way to resolve this?
>
> Thanks,
> Josh
>
--
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.03175 seconds