openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Help with FieldMapping metadata
Date Tue, 07 Jul 2009 23:06:24 GMT
Hi,

I've got two classes with a one-many relationship based on column  
values, but there's no foreign key.

I've looked up the ClassMapping and FieldMapping for the fields in the  
"many" class and have the FieldMapping object for the relationship  
that's mapped to the columns.

What I'm looking for is how to extract the column values from the oid  
class corresponding to the primary key of the related class.

If I can get the pk columns that correspond to the joined columns then  
I can get the corresponding FieldMapping for the primary key fields.  
But I can't find how to get either the corresponding joined columns or  
the corresponding primary key field mapping. FieldMapping has  
getJoinForeignKey but there's no foreign key, so it's null.

Seems there should be a getJoinSomething that gives me the pairs of  
<Column localColumn, Column relatedColumn> corresponding to the  
@JoinColumn annotation but I can't find it.

Any ideas?

Thanks,

Craig

/** Schema
  *
create table longlongstringfk (
  longpk1 bigint not null,
  longpk2 bigint not null,
  stringpk varchar(10) not null,
  longfk1 bigint not null,
  longfk2 bigint not null,
  stringfk varchar(10) not null,
  stringvalue varchar(10),
         CONSTRAINT PK_longlongstringfk PRIMARY KEY (longpk1, longpk2,  
stringpk)
*/

public class LongLongStringFKRelationship extends  
LongLongStringConstants implements Serializable {

     @javax.persistence.Id
     @javax.persistence.Column(name="longpk1")
     private long longpk1;

     @javax.persistence.Id
     @javax.persistence.Column(name="longpk2")
     private long longpk2;

     @javax.persistence.Id
     @javax.persistence.Column(name="stringpk")
     private String stringpk;


     @ManyToOne
     @JoinColumns({
         @JoinColumn(name="longfk1", referencedColumnName="longpk1"),
         @JoinColumn(name="longfk2", referencedColumnName="longpk2"),
         @JoinColumn(name="stringfk", referencedColumnName="stringpk")
         })
     private LongLongStringPKRelationship longLongStringPKRelationship;

Here's the related class:

/** Schema
  *
create table longlongstringpk (
  longpk1 bigint not null,
  longpk2 bigint not null,
  stringpk varchar(10) not null,
  stringvalue varchar(10),
         CONSTRAINT PK_longlongstringpk PRIMARY KEY (longpk1, longpk2,  
stringpk)

public class LongLongStringPKRelationship extends  
LongLongStringConstants implements Serializable {

     @javax.persistence.Id
     @javax.persistence.Column(name="longpk1")
     private long longpk1;

     @javax.persistence.Id
     @javax.persistence.Column(name="longpk2")
     private long longpk2;

     @javax.persistence.Id
     @javax.persistence.Column(name="stringpk")
     private String stringpk;

     @javax.persistence.Column(name="stringvalue")
     private String stringvalue;

     @OneToMany(mappedBy = "longLongStringPKRelationship")
     private Collection<LongLongStringFKRelationship>  
longLongStringFKRelationships;



Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Mime
View raw message