Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Semantics of Hibernate Bag for a non indexed many-to-many association
[Teneo] Semantics of Hibernate Bag for a non indexed many-to-many association [message #1033567] Thu, 04 April 2013 11:28 Go to next message
Josh A is currently offline Josh A
Messages: 13
Registered: September 2012
Junior Member
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?
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 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
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 #1034303 is a reply to message #1033647] Fri, 05 April 2013 09:09 Go to previous messageGo to next message
Josh A is currently offline Josh A
Messages: 13
Registered: September 2012
Junior Member
Many Thanks for your help.

I haven't used idBag annotation previously. Will read up more on it to understand the implications of setting this on a per-relationship or global basis. Currently, searching for an example that uses idBag annotation.

Thanks,
Josh
Re: [Teneo] Semantics of Hibernate Bag for a non indexed many-to-many association [message #1036353 is a reply to message #1033647] Mon, 08 April 2013 09:12 Go to previous messageGo to next message
Josh A is currently offline Josh A
Messages: 13
Registered: September 2012
Junior Member
Hi Martin,

Is there a way to specify idBag on a per-relationship level rather than globally? If so, what annotation should i use?

I tried specifying @idBag on the many-to-many relationship, but this gave me an exception "org.eclipse.emf.teneo.annotations.parser.AnnotationParserException: No eclass found with name idBag".(Presumably because "org.eclipse.emf.teneo.annotations.pannotation" package in the Teneo version i am using did not contain idBag class?)

Thanks,
Josh


Re: [Teneo] Semantics of Hibernate Bag for a non indexed many-to-many association [message #1036375 is a reply to message #1036353] Mon, 08 April 2013 09:48 Go to previous messageGo to next message
Josh A is currently offline Josh A
Messages: 13
Registered: September 2012
Junior Member
Just spotted that the right annotation should be "IdBag" rather than "idBag" i used. Will retry using the right annotation
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 Go to previous messageGo to next message
Josh A is currently offline 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 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
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
Re: [Teneo] Semantics of Hibernate Bag for a non indexed many-to-many association [message #1038067 is a reply to message #1038032] Wed, 10 April 2013 11:08 Go to previous messageGo to next message
Josh A is currently offline Josh A
Messages: 13
Registered: September 2012
Junior Member
Hi Martin,

Thanks for getting back to me. Yes, eOpposites are set in both directions. As requested, i will file this in bugzilla.

However, based on a quick check i did, inverse="true" is not supported idbag on Hibernate 3.2.7(it appears that it was introduced on later versions of Hibernate) that i am using. So, possibly i need to upgrade my version of hibernate in order to get this working.

Thanks,
Josh
Re: [Teneo] Semantics of Hibernate Bag for a non indexed many-to-many association [message #1041828 is a reply to message #1038067] Mon, 15 April 2013 16:21 Go to previous message
Josh A is currently offline Josh A
Messages: 13
Registered: September 2012
Junior Member
Raised https://bugs.eclipse.org/bugs/show_bug.cgi?id=405358
Previous Topic:Xcore and OCL
Next Topic:[CDO] How is timeout detected?
Goto Forum:
  


Current Time: Thu Oct 23 19:33:55 GMT 2014

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

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