Good afternoon,
I'm working in Adobe ColdFusion, which uses Hibernate for its ORM functionality. I've only recently started diving into the ORM universe but it seems like on the whole it's a massive time-saver! I'm just having one issue at the moment - saving an entity with an updated foreign key value.
I have already asked
a similar question on this topic on Stack Overflow, but since that point I'm starting to think the question may be more one for the Hibernate community than the ColdFusion one. The stripped-down example I gave on that question still applies, but here are similar example components for ease:
Template.cfcCode:
component persistent="true" table="template"{
property name="id" type="numeric" column="templateID" fieldtype="id" generator="identity";
property name="userID" type="numeric" fkcolumn="userID" fieldtype="many-to-one" cfc="User";
property name="lastModified" type="date" column="lastModified";
}
User.cfcCode:
component persistent="true" table="user"{
property name="id" type="numeric" column="userID" fieldtype="id" generator="identity";
property name="username" type="string" column="username";
property name="password" type="string" column="password";
}
Whenever I flush the ORM (I think this is what triggers it anyway - it's when the program attempts to update the DB) and I update template.userID I get an exception thrown, but the message is just 'java.lang.Integer' (this is the type I'm passing it, since the DB field is type 'int'). When I remove the many-to-one relationship it seems to work, making me think the issue is either with the relational mapping itself (but 'gets' work even when 'sets' don't, so probably not), the target field (again, though, gets work...) or what Hibernate has worked out the field type as.
Looking at the error dump, I can see:
CF Application error (detail:
The root cause of this exception was: coldfusion.orm.hibernate.HibernateSessionException: Property : userID - java.lang.Integer.)
caused by
java.lang.ClassCastException (message:
java.lang.integer)
caused by
org.hibernate.HibernateException (message:
Property : userID - java.lang.Integer)
Now, as I said on SO, I understand CF has a number of problems when dealing with integers, but doing a type check on the line before calling the implicit setter on userID shows it as java.lang.Integer, which is the closest CF can possibly manage to an int.
Fun fact (not sure if this affects anything) - the db table was
not created by ORM, but was already in existence when the ORM in CF was created.
I'm at the point now all I have looping in my head is "it wants an integer, I'm giving it an integer". I assume soon I'll be waking up in a cold sweat screaming "what do you want from me?" or something, but I'm also aware it may just be I've made a stupid error somewhere.
Any and all help will be greatly appreciated
Many thanks
Cush