You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Jay D. McHugh" <ja...@joyfulnoisewebdesign.com> on 2007/04/19 19:48:24 UTC
One to many relationship problem
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;
}
}
Re: Validate and @table schema use
Posted by Marc Prud'hommeaux <mp...@apache.org>.
Phill-
It sounds like a bug, but it would help to know what the exception
was :)
On Apr 23, 2007, at 7:02 AM, Phill Moran wrote:
> I have been working with the validate tool and was getting an
> exception on
> classes that used @table(name="XXX", schema="YYY"). If I took out
> the schema
> portion the exception went away. I see no mention of not using
> schema in @table
> for validate use. Is this a bug or undocumented feature
>
> The mapping tool knows which schema to use from the URL and
> openJPA.schema
> properties
>
> Phill
>
Validate and @table schema use
Posted by Phill Moran <pj...@rogers.com>.
I have been working with the validate tool and was getting an exception on
classes that used @table(name="XXX", schema="YYY"). If I took out the schema
portion the exception went away. I see no mention of not using schema in @table
for validate use. Is this a bug or undocumented feature
The mapping tool knows which schema to use from the URL and openJPA.schema
properties
Phill
Re: One to many relationship problem
Posted by "Jay D. McHugh" <ja...@joyfulnoisewebdesign.com>.
Marc,
I have several relationships that have the same target.
(table names and relationships follow)
class -(M-1)-> xClassAttrib -(1-1)-> attrib
component -(M-1)-> xCompAttrib -(1-1)-> attrib
Both of these end up at the same attrib table.
Could this be a problem?
I added some other 1-M relationships that I had not gotten to yet and
they all worked fine (actually they also used intermediate tables - that
could have played into them working).
Anyway, that is the only thing I can think of (that OpenJPA is getting
confused by having squirrelly relationships).
I finally had to just work around the problem by 'manually' querying the
table and filling the collection.
Jay
Marc Prud'hommeaux wrote:
> Jay-
>
> Something is fishy. I can't understand why it wouldn't work.
>
> Are you able to persist individual ClassAttrib instances (regardless
> of the owning ComponentClass)?
>
> Also, if you try adding a fresh new one-to-many relationship to some
> new class, is that ignored as well?
>
>
>
> On Apr 19, 2007, at 2:20 PM, Jay D. McHugh wrote:
>
>> Well,
>>
>> Removing the 'classID' field from the ClassAttrib class did not get
>> the persistence to work.
>>
>> I added the classID back to the ClassAttrib class and this time
>> annotated it (the annotation somehow got lost along the way of all my
>> tries).
>>
>> The link did not work.
>>
>> So, I tried your suggestion of trying to add ClassAttrib entities and
>> persisting them individually - the ComponentClass completely ignored
>> them - I'll play with it some more.
>>
>> Thanks for your time so far Marc.
>>
>> I'll let you know what I come up with.
>>
>> Jay
>>
>> Marc Prud'hommeaux wrote:
>>> Jay-
>>>
>>>> Nothing happened at all in between the two System.out.println's -
>>>> is there a more verbose level of logging than TRACE?
>>>
>>> No, that is showing all the SQL that OpenJPA is executing.
>>>
>>> The fact that ClassAttrib.classID is referenced as the join column,
>>> but it is an unmapped attribute in ClassAttrib gives me a little
>>> pause. Can you try commenting out that field in ClassAttrib and
>>> recompile (and re-enhance, if you are using build-time enhancement)
>>> both the classes, and see if that makes any difference?
>>>
>>> Also, what happens if you persist a new ComponentClass instance, add
>>> some entries to the ComponentClass.attributes field, and
>>> individually persist each of those instances? Do you see the
>>> expected values being inserted into the "classID" column?
>>>
>>>
>>>
>>>
>>> On Apr 19, 2007, at 11:14 AM, Jay D. McHugh wrote:
>>>
>>>> Marc,
>>>>
>>>> Here is the code block:
>>>> System.out.println("About to do a 'getAttributes' call...");
>>>> componentClass.getAttributes();
>>>> System.out.println("Finished the 'getAttributes'
>>>> call...");
>>>>
>>>> And here is the trace:
>>>> 40217 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
>>>> 32474996, conn 29265516> executing prepstmnt 566738 SELECT
>>>> t0.classDeprecated, t0.classDescription FROM class t0 WHERE
>>>> t0.classID = ? [params=(long) 1]
>>>> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
>>>> 32474996, conn 29265516> [1 ms] spent
>>>> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.JDBC - <t
>>>> 32474996, conn 29265516> [0 ms] close
>>>> About to do a 'getAttributes' call...
>>>> Finished the 'getAttributes' call...
>>>>
>>>> Nothing happened at all in between the two System.out.println's -
>>>> is there a more verbose level of logging than TRACE?
>>>>
>>>> Jay
>>>>
>>>>
>>>> Marc Prud'hommeaux wrote:
>>>>> Jay-
>>>>>
>>>>> Nothing jumps out at me as being wrong with your mapping...
>>>>>
>>>>>> Note: I don't get any errors or exceptions, just no secondary
>>>>>> queries when I do a 'find('
>>>>>
>>>>> If you call ComponentClass.getAttributes(), are you saying that no
>>>>> SQL is executed? That would be surprising. Can you enable SQL
>>>>> logging and sent the resulting SQL from some code like:
>>>>>
>>>>> ComponentClass c = em.find(ComponentClass.class, someExistingId);
>>>>> c.getAttributes();
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Apr 19, 2007, at 10:48 AM, Jay D. McHugh wrote:
>>>>>
>>>>>> 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;
>>>>>> }
>>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>
>
Re: One to many relationship problem
Posted by "Jay D. McHugh" <ja...@joyfulnoisewebdesign.com>.
I am able to persist individual ClassAttrib's without an owning
ComponentClass.
I'll try adding a new 1-1 relationship.
Jay
Marc Prud'hommeaux wrote:
> Jay-
>
> Something is fishy. I can't understand why it wouldn't work.
>
> Are you able to persist individual ClassAttrib instances (regardless
> of the owning ComponentClass)?
>
> Also, if you try adding a fresh new one-to-many relationship to some
> new class, is that ignored as well?
>
>
>
> On Apr 19, 2007, at 2:20 PM, Jay D. McHugh wrote:
>
>> Well,
>>
>> Removing the 'classID' field from the ClassAttrib class did not get
>> the persistence to work.
>>
>> I added the classID back to the ClassAttrib class and this time
>> annotated it (the annotation somehow got lost along the way of all my
>> tries).
>>
>> The link did not work.
>>
>> So, I tried your suggestion of trying to add ClassAttrib entities and
>> persisting them individually - the ComponentClass completely ignored
>> them - I'll play with it some more.
>>
>> Thanks for your time so far Marc.
>>
>> I'll let you know what I come up with.
>>
>> Jay
>>
>> Marc Prud'hommeaux wrote:
>>> Jay-
>>>
>>>> Nothing happened at all in between the two System.out.println's -
>>>> is there a more verbose level of logging than TRACE?
>>>
>>> No, that is showing all the SQL that OpenJPA is executing.
>>>
>>> The fact that ClassAttrib.classID is referenced as the join column,
>>> but it is an unmapped attribute in ClassAttrib gives me a little
>>> pause. Can you try commenting out that field in ClassAttrib and
>>> recompile (and re-enhance, if you are using build-time enhancement)
>>> both the classes, and see if that makes any difference?
>>>
>>> Also, what happens if you persist a new ComponentClass instance, add
>>> some entries to the ComponentClass.attributes field, and
>>> individually persist each of those instances? Do you see the
>>> expected values being inserted into the "classID" column?
>>>
>>>
>>>
>>>
>>> On Apr 19, 2007, at 11:14 AM, Jay D. McHugh wrote:
>>>
>>>> Marc,
>>>>
>>>> Here is the code block:
>>>> System.out.println("About to do a 'getAttributes' call...");
>>>> componentClass.getAttributes();
>>>> System.out.println("Finished the 'getAttributes'
>>>> call...");
>>>>
>>>> And here is the trace:
>>>> 40217 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
>>>> 32474996, conn 29265516> executing prepstmnt 566738 SELECT
>>>> t0.classDeprecated, t0.classDescription FROM class t0 WHERE
>>>> t0.classID = ? [params=(long) 1]
>>>> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
>>>> 32474996, conn 29265516> [1 ms] spent
>>>> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.JDBC - <t
>>>> 32474996, conn 29265516> [0 ms] close
>>>> About to do a 'getAttributes' call...
>>>> Finished the 'getAttributes' call...
>>>>
>>>> Nothing happened at all in between the two System.out.println's -
>>>> is there a more verbose level of logging than TRACE?
>>>>
>>>> Jay
>>>>
>>>>
>>>> Marc Prud'hommeaux wrote:
>>>>> Jay-
>>>>>
>>>>> Nothing jumps out at me as being wrong with your mapping...
>>>>>
>>>>>> Note: I don't get any errors or exceptions, just no secondary
>>>>>> queries when I do a 'find('
>>>>>
>>>>> If you call ComponentClass.getAttributes(), are you saying that no
>>>>> SQL is executed? That would be surprising. Can you enable SQL
>>>>> logging and sent the resulting SQL from some code like:
>>>>>
>>>>> ComponentClass c = em.find(ComponentClass.class, someExistingId);
>>>>> c.getAttributes();
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Apr 19, 2007, at 10:48 AM, Jay D. McHugh wrote:
>>>>>
>>>>>> 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;
>>>>>> }
>>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>
>
Re: One to many relationship problem
Posted by Marc Prud'hommeaux <mp...@apache.org>.
Jay-
Something is fishy. I can't understand why it wouldn't work.
Are you able to persist individual ClassAttrib instances (regardless
of the owning ComponentClass)?
Also, if you try adding a fresh new one-to-many relationship to some
new class, is that ignored as well?
On Apr 19, 2007, at 2:20 PM, Jay D. McHugh wrote:
> Well,
>
> Removing the 'classID' field from the ClassAttrib class did not get
> the persistence to work.
>
> I added the classID back to the ClassAttrib class and this time
> annotated it (the annotation somehow got lost along the way of all
> my tries).
>
> The link did not work.
>
> So, I tried your suggestion of trying to add ClassAttrib entities
> and persisting them individually - the ComponentClass completely
> ignored them - I'll play with it some more.
>
> Thanks for your time so far Marc.
>
> I'll let you know what I come up with.
>
> Jay
>
> Marc Prud'hommeaux wrote:
>> Jay-
>>
>>> Nothing happened at all in between the two System.out.println's -
>>> is there a more verbose level of logging than TRACE?
>>
>> No, that is showing all the SQL that OpenJPA is executing.
>>
>> The fact that ClassAttrib.classID is referenced as the join
>> column, but it is an unmapped attribute in ClassAttrib gives me a
>> little pause. Can you try commenting out that field in ClassAttrib
>> and recompile (and re-enhance, if you are using build-time
>> enhancement) both the classes, and see if that makes any difference?
>>
>> Also, what happens if you persist a new ComponentClass instance,
>> add some entries to the ComponentClass.attributes field, and
>> individually persist each of those instances? Do you see the
>> expected values being inserted into the "classID" column?
>>
>>
>>
>>
>> On Apr 19, 2007, at 11:14 AM, Jay D. McHugh wrote:
>>
>>> Marc,
>>>
>>> Here is the code block:
>>> System.out.println("About to do a 'getAttributes' call...");
>>> componentClass.getAttributes();
>>> System.out.println("Finished the 'getAttributes'
>>> call...");
>>>
>>> And here is the trace:
>>> 40217 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL -
>>> <t 32474996, conn 29265516> executing prepstmnt 566738 SELECT
>>> t0.classDeprecated, t0.classDescription FROM class t0 WHERE
>>> t0.classID = ? [params=(long) 1]
>>> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL -
>>> <t 32474996, conn 29265516> [1 ms] spent
>>> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.JDBC -
>>> <t 32474996, conn 29265516> [0 ms] close
>>> About to do a 'getAttributes' call...
>>> Finished the 'getAttributes' call...
>>>
>>> Nothing happened at all in between the two System.out.println's -
>>> is there a more verbose level of logging than TRACE?
>>>
>>> Jay
>>>
>>>
>>> Marc Prud'hommeaux wrote:
>>>> Jay-
>>>>
>>>> Nothing jumps out at me as being wrong with your mapping...
>>>>
>>>>> Note: I don't get any errors or exceptions, just no secondary
>>>>> queries when I do a 'find('
>>>>
>>>> If you call ComponentClass.getAttributes(), are you saying that
>>>> no SQL is executed? That would be surprising. Can you enable SQL
>>>> logging and sent the resulting SQL from some code like:
>>>>
>>>> ComponentClass c = em.find(ComponentClass.class, someExistingId);
>>>> c.getAttributes();
>>>>
>>>>
>>>>
>>>>
>>>> On Apr 19, 2007, at 10:48 AM, Jay D. McHugh wrote:
>>>>
>>>>> 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;
>>>>> }
>>>>> }
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>>
Re: One to many relationship problem
Posted by "Jay D. McHugh" <ja...@joyfulnoisewebdesign.com>.
Well,
Removing the 'classID' field from the ClassAttrib class did not get the
persistence to work.
I added the classID back to the ClassAttrib class and this time
annotated it (the annotation somehow got lost along the way of all my
tries).
The link did not work.
So, I tried your suggestion of trying to add ClassAttrib entities and
persisting them individually - the ComponentClass completely ignored
them - I'll play with it some more.
Thanks for your time so far Marc.
I'll let you know what I come up with.
Jay
Marc Prud'hommeaux wrote:
> Jay-
>
>> Nothing happened at all in between the two System.out.println's - is
>> there a more verbose level of logging than TRACE?
>
> No, that is showing all the SQL that OpenJPA is executing.
>
> The fact that ClassAttrib.classID is referenced as the join column,
> but it is an unmapped attribute in ClassAttrib gives me a little
> pause. Can you try commenting out that field in ClassAttrib and
> recompile (and re-enhance, if you are using build-time enhancement)
> both the classes, and see if that makes any difference?
>
> Also, what happens if you persist a new ComponentClass instance, add
> some entries to the ComponentClass.attributes field, and individually
> persist each of those instances? Do you see the expected values being
> inserted into the "classID" column?
>
>
>
>
> On Apr 19, 2007, at 11:14 AM, Jay D. McHugh wrote:
>
>> Marc,
>>
>> Here is the code block:
>> System.out.println("About to do a 'getAttributes' call...");
>> componentClass.getAttributes();
>> System.out.println("Finished the 'getAttributes' call...");
>>
>> And here is the trace:
>> 40217 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
>> 32474996, conn 29265516> executing prepstmnt 566738 SELECT
>> t0.classDeprecated, t0.classDescription FROM class t0 WHERE
>> t0.classID = ? [params=(long) 1]
>> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
>> 32474996, conn 29265516> [1 ms] spent
>> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.JDBC - <t
>> 32474996, conn 29265516> [0 ms] close
>> About to do a 'getAttributes' call...
>> Finished the 'getAttributes' call...
>>
>> Nothing happened at all in between the two System.out.println's - is
>> there a more verbose level of logging than TRACE?
>>
>> Jay
>>
>>
>> Marc Prud'hommeaux wrote:
>>> Jay-
>>>
>>> Nothing jumps out at me as being wrong with your mapping...
>>>
>>>> Note: I don't get any errors or exceptions, just no secondary
>>>> queries when I do a 'find('
>>>
>>> If you call ComponentClass.getAttributes(), are you saying that no
>>> SQL is executed? That would be surprising. Can you enable SQL
>>> logging and sent the resulting SQL from some code like:
>>>
>>> ComponentClass c = em.find(ComponentClass.class, someExistingId);
>>> c.getAttributes();
>>>
>>>
>>>
>>>
>>> On Apr 19, 2007, at 10:48 AM, Jay D. McHugh wrote:
>>>
>>>> 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;
>>>> }
>>>> }
>>>
>>>
>>>
>>>
>
>
>
>
Re: One to many relationship problem
Posted by Marc Prud'hommeaux <mp...@apache.org>.
Jay-
> Nothing happened at all in between the two System.out.println's -
> is there a more verbose level of logging than TRACE?
No, that is showing all the SQL that OpenJPA is executing.
The fact that ClassAttrib.classID is referenced as the join column,
but it is an unmapped attribute in ClassAttrib gives me a little
pause. Can you try commenting out that field in ClassAttrib and
recompile (and re-enhance, if you are using build-time enhancement)
both the classes, and see if that makes any difference?
Also, what happens if you persist a new ComponentClass instance, add
some entries to the ComponentClass.attributes field, and individually
persist each of those instances? Do you see the expected values being
inserted into the "classID" column?
On Apr 19, 2007, at 11:14 AM, Jay D. McHugh wrote:
> Marc,
>
> Here is the code block:
> System.out.println("About to do a 'getAttributes' call...");
> componentClass.getAttributes();
> System.out.println("Finished the 'getAttributes'
> call...");
>
> And here is the trace:
> 40217 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
> 32474996, conn 29265516> executing prepstmnt 566738 SELECT
> t0.classDeprecated, t0.classDescription FROM class t0 WHERE
> t0.classID = ? [params=(long) 1]
> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
> 32474996, conn 29265516> [1 ms] spent
> 40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.JDBC - <t
> 32474996, conn 29265516> [0 ms] close
> About to do a 'getAttributes' call...
> Finished the 'getAttributes' call...
>
> Nothing happened at all in between the two System.out.println's -
> is there a more verbose level of logging than TRACE?
>
> Jay
>
>
> Marc Prud'hommeaux wrote:
>> Jay-
>>
>> Nothing jumps out at me as being wrong with your mapping...
>>
>>> Note: I don't get any errors or exceptions, just no secondary
>>> queries when I do a 'find('
>>
>> If you call ComponentClass.getAttributes(), are you saying that no
>> SQL is executed? That would be surprising. Can you enable SQL
>> logging and sent the resulting SQL from some code like:
>>
>> ComponentClass c = em.find(ComponentClass.class, someExistingId);
>> c.getAttributes();
>>
>>
>>
>>
>> On Apr 19, 2007, at 10:48 AM, Jay D. McHugh wrote:
>>
>>> 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;
>>> }
>>> }
>>
>>
>>
>>
Re: One to many relationship problem
Posted by "Jay D. McHugh" <ja...@joyfulnoisewebdesign.com>.
Marc,
Here is the code block:
System.out.println("About to do a 'getAttributes' call...");
componentClass.getAttributes();
System.out.println("Finished the 'getAttributes' call...");
And here is the trace:
40217 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
32474996, conn 29265516> executing prepstmnt 566738 SELECT
t0.classDeprecated, t0.classDescription FROM class t0 WHERE t0.classID =
? [params=(long) 1]
40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.SQL - <t
32474996, conn 29265516> [1 ms] spent
40218 palmJPA TRACE [http-0.0.0.0-8080-4] openjpa.jdbc.JDBC - <t
32474996, conn 29265516> [0 ms] close
About to do a 'getAttributes' call...
Finished the 'getAttributes' call...
Nothing happened at all in between the two System.out.println's - is
there a more verbose level of logging than TRACE?
Jay
Marc Prud'hommeaux wrote:
> Jay-
>
> Nothing jumps out at me as being wrong with your mapping...
>
>> Note: I don't get any errors or exceptions, just no secondary queries
>> when I do a 'find('
>
> If you call ComponentClass.getAttributes(), are you saying that no SQL
> is executed? That would be surprising. Can you enable SQL logging and
> sent the resulting SQL from some code like:
>
> ComponentClass c = em.find(ComponentClass.class, someExistingId);
> c.getAttributes();
>
>
>
>
> On Apr 19, 2007, at 10:48 AM, Jay D. McHugh wrote:
>
>> 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;
>> }
>> }
>
>
>
>
Re: One to many relationship problem
Posted by Marc Prud'hommeaux <mp...@apache.org>.
Jay-
Nothing jumps out at me as being wrong with your mapping...
> Note: I don't get any errors or exceptions, just no secondary
> queries when I do a 'find('
If you call ComponentClass.getAttributes(), are you saying that no
SQL is executed? That would be surprising. Can you enable SQL logging
and sent the resulting SQL from some code like:
ComponentClass c = em.find(ComponentClass.class, someExistingId);
c.getAttributes();
On Apr 19, 2007, at 10:48 AM, Jay D. McHugh wrote:
> 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;
> }
> }