Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / November 2003

Tip: Looking for answers? Try searching our database.

Jboss XDoclet one-to-many relationship

Thread view: 
dcp - 05 Nov 2003 01:17 GMT
I am trying to set up a one to many relationship using XDoclet and
JBoss with eclipse.  But I keep getting the following error when I try
to deploy the ejb module:

Foreign key constraint is not allowed for this type of datastore]

I've included an excerpt from my bean code below.  I have a student
table and an attendance_reason table.  The attendance_reason table
will contain reasons that a student might attend the class, and it
will have two columns, a cd and desc.  Each student will have one
attendance_reason, but an attendance_reason can be related to multiple
students (i.e. one-to-many)  What I want to happen is to have an
attendance_reason_cd field in the student table that links to the cd
field in the attendance_reason table.  I'm trying to use XDoclet tags
to get the deployment descriptors generated correctly.

I'm really stuck on this and can't seem to figure it out, any advice
is greatly appreciated.  If I need to post more code, like
jbosscmp-jdbc.xml, just let me know.

Thanks.  Code excerpt follows below:

==================================
package com.paynetech.cmp;

import javax.ejb.EntityBean;

import com.paynetech.cmp.StudentUtil;

/**
* @ejb.bean name="Student"
*    jndi-name="StudentBean"
*    type="CMP"
*  primkey-field="ID"
*  schema="Student"
*  cmp-version="2.x"
*
* @ejb.persistence
*   table-name="STUDENT"
*
* @ejb.finder
*    query="SELECT OBJECT(a) FROM Student as a"  
*    signature="java.util.Collection findAll()"  
*
* @ejb.util generate="physical"
*
**/

public abstract class StudentBean implements EntityBean {
.
. <other code omitted for the sake of brevity>
.
 /**
 * @return the reason the student attends
 *    
 * @ejb.interface-method
 *
 * @ejb.relation
 *    name="Student-AttendanceReason"
 *    role-name="Student-has-AttendanceReason"
 *    target-ejb="AttendanceReason"
 *    target-role-name="AttendanceReason-belongs-to-Student"
 *    target-multiple="yes"
 *
 * @jboss.relation
 *    fk-constraint="true"
 *    fk-column="ATTENDANCE_REASON_CD"
 *    related-pk-field="CD"
 */
 public abstract AttendanceReasonLocal getAttendanceReason();

 /**
 * Sets the #1 reason the student attends
 *
 * @param AttendanceReasonLocal the new attendance reason
 *
 * @ejb.interface-method
 *
 */
 public abstract void setAttendanceReason(AttendanceReasonLocal
attendanceReasonLocal);

}
Michael Meyer - 05 Nov 2003 11:06 GMT
hi,

it looks like you want to create an unidirectional 1-n relation. I think you
should use the jboss.target-relation tag.

Michael

> I am trying to set up a one to many relationship using XDoclet and
> JBoss with eclipse.  But I keep getting the following error when I try
[quoted text clipped - 79 lines]
>
> }
dcp - 05 Nov 2003 15:03 GMT
> it looks like you want to create an unidirectional 1-n relation. I think you
> should use the jboss.target-relation tag.

Thanks, I changed the jboss.relation to jboss.target-relation, but now
I get the following error:
org.jboss.deployment.DeploymentException: CMP field for key not found:
field name=CD, ObjectName:
jboss.j2ee:jndiName=AttendanceReasonBean,service=EJB

It's like it can't find the CD field in the AttendanceReasonBean.

Here's the XDoclet tags/code with the changes I made:

/**
 * Returns the #1 reason the student attends
 * @return the #1 reason the student attends
 *    
 * @ejb.interface-method
 *
 * @ejb.relation
 *    name="Student-AttendanceReason"
 *    role-name="Student-has-AttendanceReason"
 *    target-ejb="AttendanceReason"
 *    target-role-name="AttendanceReason-belongs-to-Student"
 *    target-multiple="no"
 *
 * @jboss.target-relation
 *    fk-constraint="true"
 *    fk-column="ATTENDANCE_REASON_CD"
 *    related-pk-field="CD"
 */
 public abstract AttendanceReasonLocal getAttendanceReason();

> > I am trying to set up a one to many relationship using XDoclet and
> > JBoss with eclipse.  But I keep getting the following error when I try
[quoted text clipped - 79 lines]
> >
> > }
Michael Meyer - 06 Nov 2003 07:37 GMT
hi,

you have to map the columns of your databasetables and maybe your database
is case sensitive.

Michael

> > it looks like you want to create an unidirectional 1-n relation. I think you
> > should use the jboss.target-relation tag.
[quoted text clipped - 112 lines]
> > >
> > > }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.