I'm having difficulty getting a simple 1:n mapping working using OJB XDoclet
with Oracle and using anonymous keys. I'm sure that the solution is
straightforward but I haven't been able to find anything in the archives.
I'm also using the Maven Torque Plugin.
The parent class is Answer which has 0..* Attachment objects.
If I drop the '@ojb.reference class-ref' tag in the Attachment class (see
below), then my application builds and I can create answers with
attachments. However, no FK constraint being created in Oracle and deleting
the Answer does not auto-delete the Attachments.
Alternatively, if I attempt to force a FK in the Attachment class (see
below) I get the following error:
0 ERROR [main] XDocletMain.start - Running XDoclet failed.
0 ERROR [main] XDocletMain.start - <<Could not find the class
AttachmentImpl
on the classpath while checking the reference super in class
com.channel4.proje
cts.learning.hwh.businessobject.AttachmentImpl>>
file:D:/workspace/channel4/hwh/build-ojb.xml:86: XDoclet failed.
at xdoclet.DocletTask.start(DocletTask.java:467)
at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
at org.apache.tools.ant.Task.perform(Task.java:341)
at org.apache.tools.ant.Target.execute(Target.java:309)
at org.apache.tools.ant.Target.performTasks(Target.java:336)
at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:397)
at org.apache.tools.ant.Task.perform(Task.java:341)
at org.apache.commons.jelly.tags.ant.AntTag.doTag(AntTag.java:232)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279)
at
org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135)
at
org.apache.maven.jelly.tags.werkz.MavenGoalTag.runBodyTag(MavenGoalTa
g.java:79)
Here is an outline of the code.
------------------- Parent Class ------------------
package com.channel4.projects.learning.hwh.businessobject;
...
/**
* @ojb.class table="answer"
* proxy="dynamic"
* documentation=""
*/
public class AnswerImpl extends AbstractBusinessObject implements Answer {
/**
* @ojb.collection element-class-ref =
"com.channel4.projects.learning.hwh.businessobject.AttachmentImpl"
* collection-class =
"org.apache.ojb.broker.util.collections.ManageableHashSet"
* auto-retrieve = "false"
* auto-update = "true"
* auto-delete = "true"
* foreignkey = "answerId"
*/
private Collection attachments = new HashSet();
...
------------------- Child Class ------------------
package com.channel4.projects.learning.hwh.businessobject;
/**
* @ojb.class table="attachment"
* proxy="dynamic"
* documentation=""
* @ojb.field name="answerId"
* column="answer_id"
* jdbc-type="INTEGER"
*
* ------------------------- with this next line: XDoclet fails
* -------------------------- without it No FK constraint is created...
* @ojb.reference
class-ref="com.channel4.projects.learning.hwh.businessobject.AnswerImpl"
* foreignkey="answerId"
*/
public class AttachmentImpl extends AbstractBusinessObject
implements Attachment {
...
}
Again, any help would be greatly appreciated.
Thanks,
Paul.