openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jay D. McHugh" <...@joyfulnoisewebdesign.com>
Subject One to many relationship problem
Date Thu, 19 Apr 2007 17:48:24 GMT
Hello all,

I am trying to map a one to many relationship with the 'one' side as the 
relationship owner using @EntityJoinColumn.

Actually, I am trying to do this several times within my persistence unit.

In two cases, it seems to be working - but no matter what I do 
(including giving up on having the 'one' side own the relationship and 
push it over to the 'many' side) I cannot seem to get a third case to 
work.  It just refuses to acknowledge that there is any reference that 
needs to be followed.

Here are the two classes that are supposed to be linked - Can anyone see 
a problem with how I did this?

Note: I don't get any errors or exceptions, just no secondary queries 
when I do a 'find('

Thanks for any help,

Jay

----------- Class 1 -------------
package com.pubint.ejb.entity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.openjpa.persistence.jdbc.ElementJoinColumn;

@Entity
@Table(name="componentClass")
public class ComponentClass {
    private long classID;
    private String classDescription;
    private boolean classDeprecated;

    private Collection<ClassAttrib> attributes = new 
ArrayList<ClassAttrib>();

    public ComponentClass() {

    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="classID")
    public long getClassID() {
        return classID;
    }

    public void setClassID(long classID) {
        this.classID = classID;
    }

    @Column(name="classDescription")
    public String getClassDescription() {
        return classDescription;
    }

    public void setClassDescription(String classDescription) {
        this.classDescription = classDescription;
    }

    @Column(name="classDeprecated")
    public boolean isClassDeprecated() {
        return classDeprecated;
    }

    public void setClassDeprecated(boolean classDeprecated) {
        this.classDeprecated = classDeprecated;
    }

    @OneToMany
    @ElementJoinColumn(name="classID", referencedColumnName="classID")
    public Collection<ClassAttrib> getAttributes() {
        return attributes;
    }

    public void addAttribute(ClassAttrib attribute) {
        attributes.add(attribute);
    }
}


-------------- Class 2 --------------------
package com.pubint.ejb.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="xClassAttrib")
public class ClassAttrib {
    private long id;
    private long classID;
    private Attrib attribute;
    private long displaySequence;
    private boolean mandatory;
    private boolean requiresPrototype;
    private boolean lockedByPrototype;

    public ClassAttrib() {

    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
   
    public long getClassID() {
        return classID;
    }
   
    public void setClassID(long classID) {
        this.classID = classID;
    }

    @ManyToOne
    @JoinColumn(name="attributeID")
    public Attrib getAttribute() {
        return attribute;
    }

    public void setAttribute(Attrib attribute) {
        this.attribute = attribute;
    }

    @Column(name="displaySequence")
    public long getDisplaySequence() {
        return displaySequence;
    }

    public void setDisplaySequence(long seq) {
        displaySequence = seq;
    }

    @Column(name="mandatory")
    public boolean isMandatory() {
        return mandatory;
    }

    public void setMandatory(boolean mandatory) {
        this.mandatory = mandatory;
    }

    @Column(name="lockedByPrototype")
    public boolean isLockedByPrototype() {
        return lockedByPrototype;
    }

    public void setLockedByPrototype(boolean lockedByPrototype) {
        this.lockedByPrototype = lockedByPrototype;
    }

    @Column(name="requiresPrototype")
    public boolean isRequiresPrototype() {
        return requiresPrototype;
    }

    public void setRequiresPrototype(boolean requiresPrototype) {
        this.requiresPrototype = requiresPrototype;
    }
}

Mime
View raw message