I just ran into a strange error:
could not initialize a collection: [webServiceAction.aAssignedApplication#7]
which makes more sense after looking at the root cause:
[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'sName'
Basically, Hibernate tries to find the sort column inside the link table instead of the one table behind the referenced entity. Not sure how to tell Hibernate the correct location.
There are two entities (webServiceAction.cfc and app.cfc) linked through a table in a many-to-many relationship. Both implement a HasName.cfc interface among other interfaces..
.
Section from webServiceAction.cfc:
<cfproperty name="aAssignedApplication"
fieldtype="many-to-many"
CFC="model.app"
linktable="G_TRelWebserviceActionAssignment"
fKColumn="fkWebserviceActionID"
inversejoincolumn="fkApplicationID"
lazy="true"
cascade="delete-orphan"
orderby="sName">
.
SQL captured through a profiler listening to the MS SQL database:
select aassigneda0_.fkWebserviceActionID as fkWebser2_5_1_,
aassigneda0_.fkApplicationID as fkApplic1_1_,
app1_.pkApplicationID as pkApplic1_0_0_,
app1_.sName as sName0_0_,
app1_.sUUID as sUUID0_0_,
app1_.sToken as sToken0_0_,
app1_.sDescription as sDescrip5_0_0_,
app1_.dCreateDate as dCreateD6_0_0_
from G_TRelWebserviceActionAssignment aassigneda0_
inner join G_TApplication app1_ on aassigneda0_.fkApplicationID=app1_.pkApplicationID
where aassigneda0_.fkWebserviceActionID=?
order by aassigneda0_.sName
As you can see from the last line in the SQL block, Hibernate ends up trying to find the name column in the link table instead of the actual table behind the app.cfc objects.
I’ve already tried a more specific notation by prepending it with the entity and table names, but those attempts didn’t work out either.
Thanks in advance for any attempts to point me in the right direction.
I’d probably be able to fix it using a formula or by writing the XML file myself, but I’d like to avoid that, if possible.
Addendum:
My cascade settings were too aggressive and cascade="save-update" is enough for this task, but the main problem still exists.
this is expected behavior in hibernate if you set the order by in the set definition. there is also an orderby in the manytomanydefinition which does what you want, but i do not know how to state this in coldfusion