You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by jeff <je...@yahoo.com> on 2007/04/02 19:41:46 UTC

composite ID w/ another composite ID as a field

say i have Library, Book, and Page classes. a Library has many Books, and a Book has many Pages. A Library's ID is it's name (simple). A Book's ID is a composite of it's name and it's owning Library's name (bidirectional relationship). A Page's ID is a composite of it's number and it's owning Book's ID, a BookID.

so, the PageId class starts like:

public class PageId implements Serializable {
    private int number;
    private BookId book;

the error i'm getting is at runtime ...

<4|true|0.9.6-incubating> org.apache.openjpa.persistence.ArgumentException: Field "com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book" as its mapped-by field, but this field is not a direct relation.

first, is what i'm trying to do even valid? i suspect it is not, and the problem is that the fields of the ID class must be "simple" types  (i believe the spec demands that). although, the error message is a little confusing so i am not sure.

it occurs to me that another way to achieve this would be to add bookName and libraryName fields to the Page class, and add a @PrePersist method that populates them by calling book.getName() and book.getLibrary().getName(). but again this is messy because that data is already in the table because of the bidirectional relationship between the objects.

as always, i'm open to "what are you an idiot?" responses if i am just going about trying to define the Library, Book, Page relationship in an obtuse manner.

classes attached.

 
---------------------------------
The fish are biting.
 Get more visitors on your site using Yahoo! Search Marketing.

Re: composite ID w/ another composite ID as a field

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
  SVN commit 678518 [1] addresses this problem. We have cannibalized your
tests also. 
It will be good if you can verify the changes with latest OpenJPA trunk
build that includes 678518 

[1] http://svn.apache.org/viewvc?view=rev&revision=678518


-- 
View this message in context: http://n2.nabble.com/composite-ID-w--another-composite-ID-as-a-field-tp213033p575486.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


RE: composite ID w/ another composite ID as a field

Posted by Pinaki Poddar <pp...@bea.com>.
Hi Jeff,
   I could reproduce the error on your test case. So please file a JIRA
issue. 


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Friday, April 06, 2007 12:57 PM
To: open-jpa-dev@incubator.apache.org
Subject: RE: composite ID w/ another composite ID as a field

hi pinaki,

should i file an issue for this one? i can attach the failing test case
there.

thanks for your help.

jeff <je...@yahoo.com> wrote: Pinaki Poddar
 wrote:  > i can also pass along a maven2 project Can you post the Java
source of the test case and domain classes for us to reproduce the
error? 
i sent a .zip of the maven2 project to you directly. if there is a
better place to post it, let me know.

afaik, Application identity classes like PageId are not enhanced in
current versions, they used to be.
i did not see any difference between the decompiled Page and PageId
classes from the failed case, and the case that works when i remove the
book field from PageId (besides the obvious ones).

Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com]
Sent: Tuesday, April 03, 2007 11:57 AM
To: open-jpa-dev@incubator.apache.org
Subject: RE: composite ID w/ another composite ID as a field

thanks pinaki,

as a test, i removed Page.book as an @Id, and made the corresponding
change in PageId (removed the book field of type PageId). this caused
the class cast exception below to go away. so, it does appear to have
some relation of to the use of the composite ID within a composite ID,
although you're right it might be a completely different issue.

this is with a trunk (as of this morning) build of openjpa.

i have attached the log you asked for. nothing stood out. i can also
pass along a maven2 project that contains the test case that fails if
that helps. i can't see to attach it here directly though as apache's
spam filter doesn't like it. let me know.

thanks again.

Pinaki Poddar
 wrote:

 Jeff,
 1. The errors look rather unrelated to original problem of composite
id.
 2. The errors apparently caused by enviroment setup, so please
 a) get a clean 0.9.7 openjpa (either building locally from the  source,
or pre-built jars from the openjpa web-site)
 b) if the error persists, report with trace-level logging  (property
name="openjpa.Log" value="DefaultLevel=TRACE"/>  and complete stack
trace.
 
 
 
 
 Pinaki Poddar
 BEA Systems
 415.402.7317 
 
 
 -----Original Message-----
 From: jeff [mailto:jeffrey.blattman@yahoo.com]
 Sent: Monday, April 02, 2007 4:12 PM
 To: open-jpa-dev@incubator.apache.org
 Subject: RE: composite ID w/ another composite ID as a field
 
 thanks pinaki,
 
 after making those changes, on 0.9.6, i get:
 
 Caused by: java.lang.ClassCastException:
 org.apache.openjpa.util.ObjectId
 at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
 at
 
org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
 at
 
org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)
 
 i built the trunk locally, and mvn installed it into my local
repository. when i run against it, i get:
 
 Caused by: java.lang.RuntimeException: There were errors initializing
your configuration: org.apache.openjpa.lib.util.ParseException:
 Instantiation of plugin "QueryCompilationCache" with value "true"
caused  an error "java.lang.IllegalArgumentException:
 java.lang.ClassNotFoundException:
org.apache.openjpa.util.CacheMap". The
 alias or class name may have been misspelled (as it closely matches the
valid plugin alias "true"), or the class may not be available in the
class path. Valid aliases for this plugin are: [all, false, true]
 
 followed by:
 
 Caused by: java.lang.IllegalArgumentException:
 java.lang.ClassNotFoundException:
org.apache.openjpa.util.CacheMap
 at serp.util.Strings.toClass(Strings.java:211)
 at serp.util.Strings.toClass(Strings.java:140)
 at
 
org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.ja
 va:191)
 
 are there known issues w/ 0.9.7? what i don't understand is that
...CacheMap is in the sample place, in the same JAR as w/ the
0.9.6
 dependency, just in my local repository.
 
 also odd is that i only see the one info message during
enhancement:
 
 [java] 1268 book INFO [main] openjpa.Tool - No targets were  given.
Running on all classes in your persistent classes list, or all  metadata
files in classpath directories if you have not listed your  persistent
classes. Use -help to display tool usage information.
 
 no details are printed about the classes being enhanced.
obviously this
 was working in version 0,9.6.
 
 any ideas?
 
 Pinaki Poddar wrote: Hello Jeff,
 
 OpenJPA supports the cited example where Page using a composite ID
which  in turn refers to Book's composite ID. 
 
 Book/Page/Library classes work with
 a) openjpa-0.9.7 (do not know whether observed errors are due to usage
of earlier 0.9.6 version)
 b) following modifications in Page.book field (with a + sign)
 
 @Id
 @Column(nullable = false)
 @ManyToOne (cascade = CascadeType.ALL)
 + @JoinColumns({
 + @JoinColumn(name="book_library_LIBRARY_NAME",
 referencedColumnName="library_LIBRARY_NAME"),
 + @JoinColumn(name="book_BOOK_NAME",
 referencedColumnName="BOOK_NAME")
 })
 private Book book;
 
 
 where the JoinColumns specification refers to following schema (as per
your Page/Book/Library class annotations):
 
 mysql> desc book;
 
+----------------------+--------------+------+-----+---------+-------+
 | Field | Type | Null | Key | Default | Extra |
 
+----------------------+--------------+------+-----+---------+-------+
 | library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL | |  |
BOOK_NAME | varchar(255) | NO | PRI | NULL | |
 
+----------------------+--------------+------+-----+---------+-------+
 mysql> desc page;
 
+---------------------------+--------------+------+-----+---------+-----
 --+
 | Field | Type | Null | Key | Default |  Extra |
 
+---------------------------+--------------+------+-----+---------+-----
 --+
 | book_library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL |  |  |
book_BOOK_NAME | varchar(255) | NO | PRI | NULL |  |  | PAGE_NUMBER |
int(11) | NO | PRI | NULL |  |
 
+---------------------------+--------------+------+-----+---------+-----
 --+
 
 
 Without explicitly naming the join columns, following error is
 generated:
 
 Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
 org.apache.openjpa.persistence.ArgumentException:
"crxxx.Page.book" does
 not supply a name for at least one declared column. Since this mapping
can involve multiple columns or uses constant joins, each column must
give either its name or a non-constant target.
 at
 
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
 a:1372)
 at
 
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
 86)
 at
 
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
 va:948)
 at
 
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
 fo.java:101)
 at
 
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
 eldStrategy.java:144)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
 117)
 at
 
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
 ntimeStrategyInstaller.java:77)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
 va:435)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
 
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
 ssMapping.java:810)
 at
 
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
 ository.java:316)
 at
 
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
 .java:602)
 at
 
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
 va:489)
 ... 24 more
 NestedThrowables:
 <4|true|0.9.7-incubating-SNAPSHOT>
 org.apache.openjpa.persistence.ArgumentException: Field
"crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by field,
but this field is not a direct relation.
 at
 
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
 y.map(RelationToManyInverseKeyFieldStrategy.java:123)
 at
 
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
 ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
 117)
 at
 
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
 ntimeStrategyInstaller.java:77)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
 va:435)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
 
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
 va:781)
 at
 
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
 ...
 
 
 Pinaki Poddar
 BEA Systems
 415.402.7317 
 
 
 -----Original Message-----
 From: jeff [mailto:jeffrey.blattman@yahoo.com]
 Sent: Monday, April 02, 2007 12:42 PM
 To: open-jpa-dev@incubator.apache.org
 Subject: composite ID w/ another composite ID as a field
 
 say i have Library, Book, and Page classes. a Library has many Books,
and a Book has many Pages. A Library's ID is it's name (simple).
A
 Book's ID is a composite of it's name and it's owning Library's name
(bidirectional relationship). A Page's ID is a composite of it's number
and it's owning Book's ID, a BookID.
 
 so, the PageId class starts like:
 
 public class PageId implements Serializable {  private int number;
private BookId book;
 
 the error i'm getting is at runtime ...
 
 <4|true|0.9.6-incubating>
 org.apache.openjpa.persistence.ArgumentException: Field
"com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book"
 as its mapped-by field, but this field is not a direct relation.
 
 first, is what i'm trying to do even valid? i suspect it is not, and
the  problem is that the fields of the ID class must be "simple"
types (i
 believe the spec demands that). although, the error message is a little
confusing so i am not sure.
 
 it occurs to me that another way to achieve this would be to add
bookName and libraryName fields to the Page class, and add a @PrePersist
method that populates them by calling book.getName() and
book.getLibrary().getName(). but again this is messy because that data
is already in the table because of the bidirectional relationship
between the objects.
 
 as always, i'm open to "what are you an idiot?" responses if i am just
going about trying to define the Library, Book, Page relationship in an
obtuse manner.
 
 classes attached.
 
 
 ________________________________
 
 The fish are biting.
 Get more visitors
 
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
 > on your site using Yahoo! Search Marketing.
 
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
 > 
 
 Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
 
 
 ---------------------------------
 Need Mail bonding?
 Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
 
 Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
 


________________________________

Food fight?
wOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&s
id=396545367>  Enjoy some healthy debate in the Yahoo! Answers Food &
Drink Q&A.
wOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&s
id=396545367> 

Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.



 
---------------------------------
No need to miss a message. Get email on-the-go with Yahoo! Mail for
Mobile. Get started.


 
---------------------------------
No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

RE: composite ID w/ another composite ID as a field

Posted by jeff <je...@yahoo.com>.
hi pinaki,

should i file an issue for this one? i can attach the failing test case there.

thanks for your help.

jeff <je...@yahoo.com> wrote: Pinaki Poddar 
 wrote:  > i can also pass along a maven2 project 
Can you post the Java source of the test case and domain classes for us
to reproduce the error? 
i sent a .zip of the maven2 project to you directly. if there is a better place to post it, let me know.

afaik, Application identity classes like PageId are not enhanced in
current versions, they used to be.
i did not see any difference between the decompiled Page and PageId classes from the failed case, and the case that works when i remove the book field from PageId (besides the obvious ones).

Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Tuesday, April 03, 2007 11:57 AM
To: open-jpa-dev@incubator.apache.org
Subject: RE: composite ID w/ another composite ID as a field

thanks pinaki,

as a test, i removed Page.book as an @Id, and made the corresponding
change in PageId (removed the book field of type PageId). this caused
the class cast exception below to go away. so, it does appear to have
some relation of to the use of the composite ID within a composite ID,
although you're right it might be a completely different issue.

this is with a trunk (as of this morning) build of openjpa.

i have attached the log you asked for. nothing stood out. i can also
pass along a maven2 project that contains the test case that fails if
that helps. i can't see to attach it here directly though as apache's
spam filter doesn't like it. let me know.

thanks again.

Pinaki Poddar 
 wrote:

 Jeff,
 1. The errors look rather unrelated to original problem of
composite
 id.
 2. The errors apparently caused by enviroment setup, so please
 a) get a clean 0.9.7 openjpa (either building locally from the
 source, or pre-built jars from the openjpa web-site)
 b) if the error persists, report with trace-level logging
 (property name="openjpa.Log" value="DefaultLevel=TRACE"/> 
 and complete stack trace.
 
 
 
 
 Pinaki Poddar
 BEA Systems
 415.402.7317 
 
 
 -----Original Message-----
 From: jeff [mailto:jeffrey.blattman@yahoo.com] 
 Sent: Monday, April 02, 2007 4:12 PM
 To: open-jpa-dev@incubator.apache.org
 Subject: RE: composite ID w/ another composite ID as a field
 
 thanks pinaki,
 
 after making those changes, on 0.9.6, i get:
 
 Caused by: java.lang.ClassCastException:
 org.apache.openjpa.util.ObjectId
 at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
 at
 
org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
 at
 
org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)
 
 i built the trunk locally, and mvn installed it into my local
 repository. when i run against it, i get:
 
 Caused by: java.lang.RuntimeException: There were errors
initializing
 your configuration: org.apache.openjpa.lib.util.ParseException:
 Instantiation of plugin "QueryCompilationCache" with value
"true" caused
 an error "java.lang.IllegalArgumentException:
 java.lang.ClassNotFoundException:
org.apache.openjpa.util.CacheMap". The
 alias or class name may have been misspelled (as it closely
matches the
 valid plugin alias "true"), or the class may not be available in
the
 class path. Valid aliases for this plugin are: [all, false,
true]
 
 followed by:
 
 Caused by: java.lang.IllegalArgumentException:
 java.lang.ClassNotFoundException:
org.apache.openjpa.util.CacheMap
 at serp.util.Strings.toClass(Strings.java:211)
 at serp.util.Strings.toClass(Strings.java:140)
 at
 
org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.ja
 va:191)
 
 are there known issues w/ 0.9.7? what i don't understand is that
 ...CacheMap is in the sample place, in the same JAR as w/ the
0.9.6
 dependency, just in my local repository.
 
 also odd is that i only see the one info message during
enhancement:
 
 [java] 1268 book INFO [main] openjpa.Tool - No targets were
 given. Running on all classes in your persistent classes list,
or all
 metadata files in classpath directories if you have not listed
your
 persistent classes. Use -help to display tool usage information.
 
 no details are printed about the classes being enhanced.
obviously this
 was working in version 0,9.6.
 
 any ideas?
 
 Pinaki Poddar wrote: Hello Jeff,
 
 OpenJPA supports the cited example where Page using a composite
ID which
 in turn refers to Book's composite ID. 
 
 Book/Page/Library classes work with
 a) openjpa-0.9.7 (do not know whether observed errors are due to
usage
 of earlier 0.9.6 version)
 b) following modifications in Page.book field (with a + sign)
 
 @Id
 @Column(nullable = false)
 @ManyToOne (cascade = CascadeType.ALL)
 + @JoinColumns({
 + @JoinColumn(name="book_library_LIBRARY_NAME",
 referencedColumnName="library_LIBRARY_NAME"),
 + @JoinColumn(name="book_BOOK_NAME",
 referencedColumnName="BOOK_NAME")
 })
 private Book book;
 
 
 where the JoinColumns specification refers to following schema
(as per
 your Page/Book/Library class annotations):
 
 mysql> desc book;
 
+----------------------+--------------+------+-----+---------+-------+
 | Field | Type | Null | Key | Default | Extra |
 
+----------------------+--------------+------+-----+---------+-------+
 | library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL | |
 | BOOK_NAME | varchar(255) | NO | PRI | NULL | |
 
+----------------------+--------------+------+-----+---------+-------+
 mysql> desc page;
 
+---------------------------+--------------+------+-----+---------+-----
 --+
 | Field | Type | Null | Key | Default |
 Extra |
 
+---------------------------+--------------+------+-----+---------+-----
 --+
 | book_library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL |
 |
 | book_BOOK_NAME | varchar(255) | NO | PRI | NULL |
 |
 | PAGE_NUMBER | int(11) | NO | PRI | NULL |
 |
 
+---------------------------+--------------+------+-----+---------+-----
 --+
 
 
 Without explicitly naming the join columns, following error is
 generated:
 
 Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
 org.apache.openjpa.persistence.ArgumentException:
"crxxx.Page.book" does
 not supply a name for at least one declared column. Since this
mapping
 can involve multiple columns or uses constant joins, each column
must
 give either its name or a non-constant target.
 at
 
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
 a:1372)
 at
 
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
 86)
 at
 
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
 va:948)
 at
 
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
 fo.java:101)
 at
 
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
 eldStrategy.java:144)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
 117)
 at
 
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
 ntimeStrategyInstaller.java:77)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
 va:435)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
 
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
 ssMapping.java:810)
 at
 
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
 ository.java:316)
 at
 
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
 .java:602)
 at
 
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
 va:489)
 ... 24 more
 NestedThrowables:
 <4|true|0.9.7-incubating-SNAPSHOT>
 org.apache.openjpa.persistence.ArgumentException: Field
 "crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by
field,
 but this field is not a direct relation.
 at
 
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
 y.map(RelationToManyInverseKeyFieldStrategy.java:123)
 at
 
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
 ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
 117)
 at
 
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
 ntimeStrategyInstaller.java:77)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
 va:435)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
 
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
 va:781)
 at
 
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
 ...
 
 
 Pinaki Poddar
 BEA Systems
 415.402.7317 
 
 
 -----Original Message-----
 From: jeff [mailto:jeffrey.blattman@yahoo.com]
 Sent: Monday, April 02, 2007 12:42 PM
 To: open-jpa-dev@incubator.apache.org
 Subject: composite ID w/ another composite ID as a field
 
 say i have Library, Book, and Page classes. a Library has many
Books,
 and a Book has many Pages. A Library's ID is it's name (simple).
A
 Book's ID is a composite of it's name and it's owning Library's
name
 (bidirectional relationship). A Page's ID is a composite of it's
number
 and it's owning Book's ID, a BookID.
 
 so, the PageId class starts like:
 
 public class PageId implements Serializable {
 private int number;
 private BookId book;
 
 the error i'm getting is at runtime ...
 
 <4|true|0.9.6-incubating>
 org.apache.openjpa.persistence.ArgumentException: Field
 "com.mycompany.book.Book.pages" declares
"com.mycompany.book.Page.book"
 as its mapped-by field, but this field is not a direct relation.
 
 first, is what i'm trying to do even valid? i suspect it is not,
and the
 problem is that the fields of the ID class must be "simple"
types (i
 believe the spec demands that). although, the error message is a
little
 confusing so i am not sure.
 
 it occurs to me that another way to achieve this would be to add
 bookName and libraryName fields to the Page class, and add a
@PrePersist
 method that populates them by calling book.getName() and
 book.getLibrary().getName(). but again this is messy because
that data
 is already in the table because of the bidirectional
relationship
 between the objects.
 
 as always, i'm open to "what are you an idiot?" responses if i
am just
 going about trying to define the Library, Book, Page
relationship in an
 obtuse manner.
 
 classes attached.
 
 
 ________________________________
 
 The fish are biting.
 Get more visitors
 
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
 > on your site using Yahoo! Search Marketing.
 
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
 > 
 
 Notice: This email message, together with any attachments, may
contain
 information of BEA Systems, Inc., its subsidiaries and
affiliated
 entities, that may be confidential, proprietary, copyrighted
and/or
 legally privileged, and is intended solely for the use of the
individual
 or entity named in this message. If you are not the intended
recipient,
 and have received this message in error, please immediately
return this
 by email and then delete it.
 
 
 ---------------------------------
 Need Mail bonding?
 Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers
users.
 
 Notice: This email message, together with any attachments, may
contain information of BEA Systems, Inc., its subsidiaries and
affiliated entities, that may be confidential, proprietary, copyrighted
and/or legally privileged, and is intended solely for the use of the
individual or entity named in this message. If you are not the intended
recipient, and have received this message in error, please immediately
return this by email and then delete it.
 


________________________________

Food fight?
wOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&s
id=396545367>  Enjoy some healthy debate in the Yahoo! Answers Food &
Drink Q&A.
wOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&s
id=396545367> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.



 
---------------------------------
No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.


 
---------------------------------
No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.

RE: composite ID w/ another composite ID as a field

Posted by jeff <je...@yahoo.com>.
Pinaki Poddar <pp...@bea.com> wrote:  > i can also pass along a maven2 project 
Can you post the Java source of the test case and domain classes for us
to reproduce the error? 
i sent a .zip of the maven2 project to you directly. if there is a better place to post it, let me know.

afaik, Application identity classes like PageId are not enhanced in
current versions, they used to be.
i did not see any difference between the decompiled Page and PageId classes from the failed case, and the case that works when i remove the book field from PageId (besides the obvious ones).

Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Tuesday, April 03, 2007 11:57 AM
To: open-jpa-dev@incubator.apache.org
Subject: RE: composite ID w/ another composite ID as a field

thanks pinaki,

as a test, i removed Page.book as an @Id, and made the corresponding
change in PageId (removed the book field of type PageId). this caused
the class cast exception below to go away. so, it does appear to have
some relation of to the use of the composite ID within a composite ID,
although you're right it might be a completely different issue.

this is with a trunk (as of this morning) build of openjpa.

i have attached the log you asked for. nothing stood out. i can also
pass along a maven2 project that contains the test case that fails if
that helps. i can't see to attach it here directly though as apache's
spam filter doesn't like it. let me know.

thanks again.

Pinaki Poddar 
 wrote:

 Jeff,
 1. The errors look rather unrelated to original problem of
composite
 id.
 2. The errors apparently caused by enviroment setup, so please
 a) get a clean 0.9.7 openjpa (either building locally from the
 source, or pre-built jars from the openjpa web-site)
 b) if the error persists, report with trace-level logging
 (property name="openjpa.Log" value="DefaultLevel=TRACE"/> 
 and complete stack trace.
 
 
 
 
 Pinaki Poddar
 BEA Systems
 415.402.7317 
 
 
 -----Original Message-----
 From: jeff [mailto:jeffrey.blattman@yahoo.com] 
 Sent: Monday, April 02, 2007 4:12 PM
 To: open-jpa-dev@incubator.apache.org
 Subject: RE: composite ID w/ another composite ID as a field
 
 thanks pinaki,
 
 after making those changes, on 0.9.6, i get:
 
 Caused by: java.lang.ClassCastException:
 org.apache.openjpa.util.ObjectId
 at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
 at
 
org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
 at
 
org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)
 
 i built the trunk locally, and mvn installed it into my local
 repository. when i run against it, i get:
 
 Caused by: java.lang.RuntimeException: There were errors
initializing
 your configuration: org.apache.openjpa.lib.util.ParseException:
 Instantiation of plugin "QueryCompilationCache" with value
"true" caused
 an error "java.lang.IllegalArgumentException:
 java.lang.ClassNotFoundException:
org.apache.openjpa.util.CacheMap". The
 alias or class name may have been misspelled (as it closely
matches the
 valid plugin alias "true"), or the class may not be available in
the
 class path. Valid aliases for this plugin are: [all, false,
true]
 
 followed by:
 
 Caused by: java.lang.IllegalArgumentException:
 java.lang.ClassNotFoundException:
org.apache.openjpa.util.CacheMap
 at serp.util.Strings.toClass(Strings.java:211)
 at serp.util.Strings.toClass(Strings.java:140)
 at
 
org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.ja
 va:191)
 
 are there known issues w/ 0.9.7? what i don't understand is that
 ...CacheMap is in the sample place, in the same JAR as w/ the
0.9.6
 dependency, just in my local repository.
 
 also odd is that i only see the one info message during
enhancement:
 
 [java] 1268 book INFO [main] openjpa.Tool - No targets were
 given. Running on all classes in your persistent classes list,
or all
 metadata files in classpath directories if you have not listed
your
 persistent classes. Use -help to display tool usage information.
 
 no details are printed about the classes being enhanced.
obviously this
 was working in version 0,9.6.
 
 any ideas?
 
 Pinaki Poddar wrote: Hello Jeff,
 
 OpenJPA supports the cited example where Page using a composite
ID which
 in turn refers to Book's composite ID. 
 
 Book/Page/Library classes work with
 a) openjpa-0.9.7 (do not know whether observed errors are due to
usage
 of earlier 0.9.6 version)
 b) following modifications in Page.book field (with a + sign)
 
 @Id
 @Column(nullable = false)
 @ManyToOne (cascade = CascadeType.ALL)
 + @JoinColumns({
 + @JoinColumn(name="book_library_LIBRARY_NAME",
 referencedColumnName="library_LIBRARY_NAME"),
 + @JoinColumn(name="book_BOOK_NAME",
 referencedColumnName="BOOK_NAME")
 })
 private Book book;
 
 
 where the JoinColumns specification refers to following schema
(as per
 your Page/Book/Library class annotations):
 
 mysql> desc book;
 
+----------------------+--------------+------+-----+---------+-------+
 | Field | Type | Null | Key | Default | Extra |
 
+----------------------+--------------+------+-----+---------+-------+
 | library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL | |
 | BOOK_NAME | varchar(255) | NO | PRI | NULL | |
 
+----------------------+--------------+------+-----+---------+-------+
 mysql> desc page;
 
+---------------------------+--------------+------+-----+---------+-----
 --+
 | Field | Type | Null | Key | Default |
 Extra |
 
+---------------------------+--------------+------+-----+---------+-----
 --+
 | book_library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL |
 |
 | book_BOOK_NAME | varchar(255) | NO | PRI | NULL |
 |
 | PAGE_NUMBER | int(11) | NO | PRI | NULL |
 |
 
+---------------------------+--------------+------+-----+---------+-----
 --+
 
 
 Without explicitly naming the join columns, following error is
 generated:
 
 Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
 org.apache.openjpa.persistence.ArgumentException:
"crxxx.Page.book" does
 not supply a name for at least one declared column. Since this
mapping
 can involve multiple columns or uses constant joins, each column
must
 give either its name or a non-constant target.
 at
 
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
 a:1372)
 at
 
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
 86)
 at
 
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
 va:948)
 at
 
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
 fo.java:101)
 at
 
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
 eldStrategy.java:144)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
 117)
 at
 
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
 ntimeStrategyInstaller.java:77)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
 va:435)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
 
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
 ssMapping.java:810)
 at
 
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
 ository.java:316)
 at
 
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
 .java:602)
 at
 
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
 va:489)
 ... 24 more
 NestedThrowables:
 <4|true|0.9.7-incubating-SNAPSHOT>
 org.apache.openjpa.persistence.ArgumentException: Field
 "crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by
field,
 but this field is not a direct relation.
 at
 
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
 y.map(RelationToManyInverseKeyFieldStrategy.java:123)
 at
 
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
 ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
 117)
 at
 
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
 ntimeStrategyInstaller.java:77)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
 va:435)
 at
 
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
 
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
 va:781)
 at
 
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
 ...
 
 
 Pinaki Poddar
 BEA Systems
 415.402.7317 
 
 
 -----Original Message-----
 From: jeff [mailto:jeffrey.blattman@yahoo.com]
 Sent: Monday, April 02, 2007 12:42 PM
 To: open-jpa-dev@incubator.apache.org
 Subject: composite ID w/ another composite ID as a field
 
 say i have Library, Book, and Page classes. a Library has many
Books,
 and a Book has many Pages. A Library's ID is it's name (simple).
A
 Book's ID is a composite of it's name and it's owning Library's
name
 (bidirectional relationship). A Page's ID is a composite of it's
number
 and it's owning Book's ID, a BookID.
 
 so, the PageId class starts like:
 
 public class PageId implements Serializable {
 private int number;
 private BookId book;
 
 the error i'm getting is at runtime ...
 
 <4|true|0.9.6-incubating>
 org.apache.openjpa.persistence.ArgumentException: Field
 "com.mycompany.book.Book.pages" declares
"com.mycompany.book.Page.book"
 as its mapped-by field, but this field is not a direct relation.
 
 first, is what i'm trying to do even valid? i suspect it is not,
and the
 problem is that the fields of the ID class must be "simple"
types (i
 believe the spec demands that). although, the error message is a
little
 confusing so i am not sure.
 
 it occurs to me that another way to achieve this would be to add
 bookName and libraryName fields to the Page class, and add a
@PrePersist
 method that populates them by calling book.getName() and
 book.getLibrary().getName(). but again this is messy because
that data
 is already in the table because of the bidirectional
relationship
 between the objects.
 
 as always, i'm open to "what are you an idiot?" responses if i
am just
 going about trying to define the Library, Book, Page
relationship in an
 obtuse manner.
 
 classes attached.
 
 
 ________________________________
 
 The fish are biting.
 Get more visitors
 
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
 > on your site using Yahoo! Search Marketing.
 
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
 > 
 
 Notice: This email message, together with any attachments, may
contain
 information of BEA Systems, Inc., its subsidiaries and
affiliated
 entities, that may be confidential, proprietary, copyrighted
and/or
 legally privileged, and is intended solely for the use of the
individual
 or entity named in this message. If you are not the intended
recipient,
 and have received this message in error, please immediately
return this
 by email and then delete it.
 
 
 ---------------------------------
 Need Mail bonding?
 Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers
users.
 
 Notice: This email message, together with any attachments, may
contain information of BEA Systems, Inc., its subsidiaries and
affiliated entities, that may be confidential, proprietary, copyrighted
and/or legally privileged, and is intended solely for the use of the
individual or entity named in this message. If you are not the intended
recipient, and have received this message in error, please immediately
return this by email and then delete it.
 


________________________________

Food fight?
wOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&s
id=396545367>  Enjoy some healthy debate in the Yahoo! Answers Food &
Drink Q&A.
wOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&s
id=396545367> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.



 
---------------------------------
No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.

RE: composite ID w/ another composite ID as a field

Posted by Pinaki Poddar <pp...@bea.com>.
 > i can also pass along a maven2 project 
Can you post the Java source of the test case and domain classes for us
to reproduce the error? 

afaik, Application identity classes like PageId are not enhanced in
current versions, they used to be.


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Tuesday, April 03, 2007 11:57 AM
To: open-jpa-dev@incubator.apache.org
Subject: RE: composite ID w/ another composite ID as a field

thanks pinaki,

as a test, i removed Page.book as an @Id, and made the corresponding
change in PageId (removed the book field of type PageId). this caused
the class cast exception below to go away. so, it does appear to have
some relation of to the use of the composite ID within a composite ID,
although you're right it might be a completely different issue.

this is with a trunk (as of this morning) build of openjpa.

i have attached the log you asked for. nothing stood out. i can also
pass along a maven2 project that contains the test case that fails if
that helps. i can't see to attach it here directly though as apache's
spam filter doesn't like it. let me know.

thanks again.

Pinaki Poddar <pp...@bea.com> wrote:

	Jeff,
	1. The errors look rather unrelated to original problem of
composite
	id.
	2. The errors apparently caused by enviroment setup, so please
	a) get a clean 0.9.7 openjpa (either building locally from the
	source, or pre-built jars from the openjpa web-site)
	b) if the error persists, report with trace-level logging
	(property name="openjpa.Log" value="DefaultLevel=TRACE"/> 
	and complete stack trace.
	
	
	
	
	Pinaki Poddar
	BEA Systems
	415.402.7317 
	
	
	-----Original Message-----
	From: jeff [mailto:jeffrey.blattman@yahoo.com] 
	Sent: Monday, April 02, 2007 4:12 PM
	To: open-jpa-dev@incubator.apache.org
	Subject: RE: composite ID w/ another composite ID as a field
	
	thanks pinaki,
	
	after making those changes, on 0.9.6, i get:
	
	Caused by: java.lang.ClassCastException:
	org.apache.openjpa.util.ObjectId
	at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
	at
	
org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
	at
	
org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)
	
	i built the trunk locally, and mvn installed it into my local
	repository. when i run against it, i get:
	
	Caused by: java.lang.RuntimeException: There were errors
initializing
	your configuration: org.apache.openjpa.lib.util.ParseException:
	Instantiation of plugin "QueryCompilationCache" with value
"true" caused
	an error "java.lang.IllegalArgumentException:
	java.lang.ClassNotFoundException:
org.apache.openjpa.util.CacheMap". The
	alias or class name may have been misspelled (as it closely
matches the
	valid plugin alias "true"), or the class may not be available in
the
	class path. Valid aliases for this plugin are: [all, false,
true]
	
	followed by:
	
	Caused by: java.lang.IllegalArgumentException:
	java.lang.ClassNotFoundException:
org.apache.openjpa.util.CacheMap
	at serp.util.Strings.toClass(Strings.java:211)
	at serp.util.Strings.toClass(Strings.java:140)
	at
	
org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.ja
	va:191)
	
	are there known issues w/ 0.9.7? what i don't understand is that
	...CacheMap is in the sample place, in the same JAR as w/ the
0.9.6
	dependency, just in my local repository.
	
	also odd is that i only see the one info message during
enhancement:
	
	[java] 1268 book INFO [main] openjpa.Tool - No targets were
	given. Running on all classes in your persistent classes list,
or all
	metadata files in classpath directories if you have not listed
your
	persistent classes. Use -help to display tool usage information.
	
	no details are printed about the classes being enhanced.
obviously this
	was working in version 0,9.6.
	
	any ideas?
	
	Pinaki Poddar wrote: Hello Jeff,
	
	OpenJPA supports the cited example where Page using a composite
ID which
	in turn refers to Book's composite ID. 
	
	Book/Page/Library classes work with
	a) openjpa-0.9.7 (do not know whether observed errors are due to
usage
	of earlier 0.9.6 version)
	b) following modifications in Page.book field (with a + sign)
	
	@Id
	@Column(nullable = false)
	@ManyToOne (cascade = CascadeType.ALL)
	+ @JoinColumns({
	+ @JoinColumn(name="book_library_LIBRARY_NAME",
	referencedColumnName="library_LIBRARY_NAME"),
	+ @JoinColumn(name="book_BOOK_NAME",
	referencedColumnName="BOOK_NAME")
	})
	private Book book;
	
	
	where the JoinColumns specification refers to following schema
(as per
	your Page/Book/Library class annotations):
	
	mysql> desc book;
	
+----------------------+--------------+------+-----+---------+-------+
	| Field | Type | Null | Key | Default | Extra |
	
+----------------------+--------------+------+-----+---------+-------+
	| library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL | |
	| BOOK_NAME | varchar(255) | NO | PRI | NULL | |
	
+----------------------+--------------+------+-----+---------+-------+
	mysql> desc page;
	
+---------------------------+--------------+------+-----+---------+-----
	--+
	| Field | Type | Null | Key | Default |
	Extra |
	
+---------------------------+--------------+------+-----+---------+-----
	--+
	| book_library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL |
	|
	| book_BOOK_NAME | varchar(255) | NO | PRI | NULL |
	|
	| PAGE_NUMBER | int(11) | NO | PRI | NULL |
	|
	
+---------------------------+--------------+------+-----+---------+-----
	--+
	
	
	Without explicitly naming the join columns, following error is
	generated:
	
	Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
	org.apache.openjpa.persistence.ArgumentException:
"crxxx.Page.book" does
	not supply a name for at least one declared column. Since this
mapping
	can involve multiple columns or uses constant joins, each column
must
	give either its name or a non-constant target.
	at
	
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
	a:1372)
	at
	
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
	86)
	at
	
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
	va:948)
	at
	
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
	fo.java:101)
	at
	
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
	eldStrategy.java:144)
	at
	
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
	117)
	at
	
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
	ntimeStrategyInstaller.java:77)
	at
	
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
	va:435)
	at
	
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
	at
	
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
	ssMapping.java:810)
	at
	
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
	ository.java:316)
	at
	
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
	.java:602)
	at
	
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
	va:489)
	... 24 more
	NestedThrowables:
	<4|true|0.9.7-incubating-SNAPSHOT>
	org.apache.openjpa.persistence.ArgumentException: Field
	"crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by
field,
	but this field is not a direct relation.
	at
	
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
	y.map(RelationToManyInverseKeyFieldStrategy.java:123)
	at
	
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
	ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
	at
	
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
	117)
	at
	
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
	ntimeStrategyInstaller.java:77)
	at
	
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
	va:435)
	at
	
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
	at
	
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
	va:781)
	at
	
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
	...
	
	
	Pinaki Poddar
	BEA Systems
	415.402.7317 
	
	
	-----Original Message-----
	From: jeff [mailto:jeffrey.blattman@yahoo.com]
	Sent: Monday, April 02, 2007 12:42 PM
	To: open-jpa-dev@incubator.apache.org
	Subject: composite ID w/ another composite ID as a field
	
	say i have Library, Book, and Page classes. a Library has many
Books,
	and a Book has many Pages. A Library's ID is it's name (simple).
A
	Book's ID is a composite of it's name and it's owning Library's
name
	(bidirectional relationship). A Page's ID is a composite of it's
number
	and it's owning Book's ID, a BookID.
	
	so, the PageId class starts like:
	
	public class PageId implements Serializable {
	private int number;
	private BookId book;
	
	the error i'm getting is at runtime ...
	
	<4|true|0.9.6-incubating>
	org.apache.openjpa.persistence.ArgumentException: Field
	"com.mycompany.book.Book.pages" declares
"com.mycompany.book.Page.book"
	as its mapped-by field, but this field is not a direct relation.
	
	first, is what i'm trying to do even valid? i suspect it is not,
and the
	problem is that the fields of the ID class must be "simple"
types (i
	believe the spec demands that). although, the error message is a
little
	confusing so i am not sure.
	
	it occurs to me that another way to achieve this would be to add
	bookName and libraryName fields to the Page class, and add a
@PrePersist
	method that populates them by calling book.getName() and
	book.getLibrary().getName(). but again this is messy because
that data
	is already in the table because of the bidirectional
relationship
	between the objects.
	
	as always, i'm open to "what are you an idiot?" responses if i
am just
	going about trying to define the Library, Book, Page
relationship in an
	obtuse manner.
	
	classes attached.
	
	
	________________________________
	
	The fish are biting.
	Get more visitors
	
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
	> on your site using Yahoo! Search Marketing.
	
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
	> 
	
	Notice: This email message, together with any attachments, may
contain
	information of BEA Systems, Inc., its subsidiaries and
affiliated
	entities, that may be confidential, proprietary, copyrighted
and/or
	legally privileged, and is intended solely for the use of the
individual
	or entity named in this message. If you are not the intended
recipient,
	and have received this message in error, please immediately
return this
	by email and then delete it.
	
	
	---------------------------------
	Need Mail bonding?
	Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers
users.
	
	Notice: This email message, together with any attachments, may
contain information of BEA Systems, Inc., its subsidiaries and
affiliated entities, that may be confidential, proprietary, copyrighted
and/or legally privileged, and is intended solely for the use of the
individual or entity named in this message. If you are not the intended
recipient, and have received this message in error, please immediately
return this by email and then delete it.
	


________________________________

Food fight?
<http://answers.yahoo.com/dir/index;_ylc=X3oDMTFvbGNhMGE3BF9TAzM5NjU0NTE
wOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&s
id=396545367>  Enjoy some healthy debate in the Yahoo! Answers Food &
Drink Q&A.
<http://answers.yahoo.com/dir/index;_ylc=X3oDMTFvbGNhMGE3BF9TAzM5NjU0NTE
wOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&s
id=396545367> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

RE: composite ID w/ another composite ID as a field

Posted by jeff <je...@yahoo.com>.
thanks pinaki,

as a test, i removed Page.book as an @Id, and made the corresponding change in PageId (removed the book field of type PageId). this caused the class cast exception below to go away. so, it does appear to have some relation of to the use of the composite ID within a composite ID, although you're right it might be a completely different issue.

this is with a trunk (as of this morning) build of openjpa.

i have attached the log you asked for. nothing stood out. i can also pass along a maven2 project that contains the test case that fails if that helps. i can't see to attach it here directly though as apache's spam filter doesn't like it. let me know.

thanks again.

Pinaki Poddar <pp...@bea.com> wrote: Jeff,
   1. The errors look rather unrelated to original problem of composite
id.
   2. The errors apparently caused by enviroment setup, so please
      a) get a clean 0.9.7 openjpa (either building locally from the
source, or pre-built jars from the openjpa web-site)
      b) if the error persists, report with trace-level logging
(property name="openjpa.Log" value="DefaultLevel=TRACE"/> 
           and complete stack trace.
  
     


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Monday, April 02, 2007 4:12 PM
To: open-jpa-dev@incubator.apache.org
Subject: RE: composite ID w/ another composite ID as a field

thanks pinaki,

after making those changes, on 0.9.6, i get:

Caused by: java.lang.ClassCastException:
org.apache.openjpa.util.ObjectId
        at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
        at
org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
        at
org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)

i built the trunk locally, and mvn installed it into my local
repository. when i run against it, i get:

Caused by: java.lang.RuntimeException: There were errors initializing
your configuration: org.apache.openjpa.lib.util.ParseException:
Instantiation of plugin "QueryCompilationCache" with value "true" caused
an error "java.lang.IllegalArgumentException:
java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap". The
alias or class name may have been misspelled (as it closely matches the
valid plugin alias "true"), or the class may not be available in the
class path.  Valid aliases for this plugin are: [all, false, true]

followed by:

Caused by: java.lang.IllegalArgumentException:
java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap
        at serp.util.Strings.toClass(Strings.java:211)
        at serp.util.Strings.toClass(Strings.java:140)
        at
org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.ja
va:191)

are there known issues w/ 0.9.7? what i don't understand is that
...CacheMap is in the sample place, in the same JAR as w/ the 0.9.6
dependency, just in my local repository.

also odd is that i only see the one info message during enhancement:

     [java] 1268  book  INFO   [main] openjpa.Tool - No targets were
given.  Running on all classes in your persistent classes list, or all
metadata files in classpath directories if you have not listed your
persistent classes.  Use -help to display tool usage information.

no details are printed about the classes being enhanced. obviously this
was working in version 0,9.6.

any ideas?

Pinaki Poddar 
 wrote: Hello Jeff,

OpenJPA supports the cited example where Page using a composite ID which
in turn refers to Book's composite ID. 

Book/Page/Library classes work with
a) openjpa-0.9.7 (do not know whether observed errors are due to usage
of earlier 0.9.6 version)
b) following modifications in Page.book field (with a + sign)

    @Id
    @Column(nullable = false)
    @ManyToOne (cascade = CascadeType.ALL)
 +   @JoinColumns({
 +      @JoinColumn(name="book_library_LIBRARY_NAME",
referencedColumnName="library_LIBRARY_NAME"),
 +      @JoinColumn(name="book_BOOK_NAME",
referencedColumnName="BOOK_NAME")
    })
    private Book book;


where the JoinColumns specification refers to following schema (as per
your Page/Book/Library class annotations):

mysql> desc book;
+----------------------+--------------+------+-----+---------+-------+
| Field                | Type         | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+---------+-------+
| library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |       |
| BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |       |
+----------------------+--------------+------+-----+---------+-------+
mysql> desc page;
+---------------------------+--------------+------+-----+---------+-----
--+
| Field                     | Type         | Null | Key | Default |
Extra |
+---------------------------+--------------+------+-----+---------+-----
--+
| book_library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |
|
| book_BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |
|
| PAGE_NUMBER               | int(11)      | NO   | PRI | NULL    |
|
+---------------------------+--------------+------+-----+---------+-----
--+


Without explicitly naming the join columns, following error is
generated:

Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: "crxxx.Page.book" does
not supply a name for at least one declared column.  Since this mapping
can involve multiple columns or uses constant joins, each column must
give either its name or a non-constant target.
 at
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
a:1372)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
86)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
va:948)
 at
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
fo.java:101)
 at
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
eldStrategy.java:144)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
ssMapping.java:810)
 at
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
ository.java:316)
 at
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
.java:602)
 at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
va:489)
 ... 24 more
NestedThrowables:
<4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: Field
"crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by field,
but this field is not a direct relation.
 at
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
y.map(RelationToManyInverseKeyFieldStrategy.java:123)
 at
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
va:781)
 at
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
...


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com]
Sent: Monday, April 02, 2007 12:42 PM
To: open-jpa-dev@incubator.apache.org
Subject: composite ID w/ another composite ID as a field

say i have Library, Book, and Page classes. a Library has many Books,
and a Book has many Pages. A Library's ID is it's name (simple). A
Book's ID is a composite of it's name and it's owning Library's name
(bidirectional relationship). A Page's ID is a composite of it's number
and it's owning Book's ID, a BookID.

so, the PageId class starts like:

public class PageId implements Serializable {
    private int number;
    private BookId book;

the error i'm getting is at runtime ...

<4|true|0.9.6-incubating>
org.apache.openjpa.persistence.ArgumentException: Field
"com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book"
as its mapped-by field, but this field is not a direct relation.

first, is what i'm trying to do even valid? i suspect it is not, and the
problem is that the fields of the ID class must be "simple" types  (i
believe the spec demands that). although, the error message is a little
confusing so i am not sure.

it occurs to me that another way to achieve this would be to add
bookName and libraryName fields to the Page class, and add a @PrePersist
method that populates them by calling book.getName() and
book.getLibrary().getName(). but again this is messy because that data
is already in the table because of the bidirectional relationship
between the objects.

as always, i'm open to "what are you an idiot?" responses if i am just
going about trying to define the Library, Book, Page relationship in an
obtuse manner.

classes attached.


________________________________

The fish are biting.
Get more visitors
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
>  on your site using Yahoo! Search Marketing.
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
> 

Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.



 
---------------------------------
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.

RE: composite ID w/ another composite ID as a field

Posted by Pinaki Poddar <pp...@bea.com>.
Jeff,
   1. The errors look rather unrelated to original problem of composite
id.
   2. The errors apparently caused by enviroment setup, so please
      a) get a clean 0.9.7 openjpa (either building locally from the
source, or pre-built jars from the openjpa web-site)
      b) if the error persists, report with trace-level logging
(property name="openjpa.Log" value="DefaultLevel=TRACE"/> 
           and complete stack trace.
  
     


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Monday, April 02, 2007 4:12 PM
To: open-jpa-dev@incubator.apache.org
Subject: RE: composite ID w/ another composite ID as a field

thanks pinaki,

after making those changes, on 0.9.6, i get:

Caused by: java.lang.ClassCastException:
org.apache.openjpa.util.ObjectId
        at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
        at
org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
        at
org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)

i built the trunk locally, and mvn installed it into my local
repository. when i run against it, i get:

Caused by: java.lang.RuntimeException: There were errors initializing
your configuration: org.apache.openjpa.lib.util.ParseException:
Instantiation of plugin "QueryCompilationCache" with value "true" caused
an error "java.lang.IllegalArgumentException:
java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap". The
alias or class name may have been misspelled (as it closely matches the
valid plugin alias "true"), or the class may not be available in the
class path.  Valid aliases for this plugin are: [all, false, true]

followed by:

Caused by: java.lang.IllegalArgumentException:
java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap
        at serp.util.Strings.toClass(Strings.java:211)
        at serp.util.Strings.toClass(Strings.java:140)
        at
org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.ja
va:191)

are there known issues w/ 0.9.7? what i don't understand is that
...CacheMap is in the sample place, in the same JAR as w/ the 0.9.6
dependency, just in my local repository.

also odd is that i only see the one info message during enhancement:

     [java] 1268  book  INFO   [main] openjpa.Tool - No targets were
given.  Running on all classes in your persistent classes list, or all
metadata files in classpath directories if you have not listed your
persistent classes.  Use -help to display tool usage information.

no details are printed about the classes being enhanced. obviously this
was working in version 0,9.6.

any ideas?

Pinaki Poddar <pp...@bea.com> wrote: Hello Jeff,

OpenJPA supports the cited example where Page using a composite ID which
in turn refers to Book's composite ID. 

Book/Page/Library classes work with
a) openjpa-0.9.7 (do not know whether observed errors are due to usage
of earlier 0.9.6 version)
b) following modifications in Page.book field (with a + sign)

    @Id
    @Column(nullable = false)
    @ManyToOne (cascade = CascadeType.ALL)
 +   @JoinColumns({
 +      @JoinColumn(name="book_library_LIBRARY_NAME",
referencedColumnName="library_LIBRARY_NAME"),
 +      @JoinColumn(name="book_BOOK_NAME",
referencedColumnName="BOOK_NAME")
    })
    private Book book;


where the JoinColumns specification refers to following schema (as per
your Page/Book/Library class annotations):

mysql> desc book;
+----------------------+--------------+------+-----+---------+-------+
| Field                | Type         | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+---------+-------+
| library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |       |
| BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |       |
+----------------------+--------------+------+-----+---------+-------+
mysql> desc page;
+---------------------------+--------------+------+-----+---------+-----
--+
| Field                     | Type         | Null | Key | Default |
Extra |
+---------------------------+--------------+------+-----+---------+-----
--+
| book_library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |
|
| book_BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |
|
| PAGE_NUMBER               | int(11)      | NO   | PRI | NULL    |
|
+---------------------------+--------------+------+-----+---------+-----
--+


Without explicitly naming the join columns, following error is
generated:

Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: "crxxx.Page.book" does
not supply a name for at least one declared column.  Since this mapping
can involve multiple columns or uses constant joins, each column must
give either its name or a non-constant target.
 at
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
a:1372)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
86)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
va:948)
 at
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
fo.java:101)
 at
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
eldStrategy.java:144)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
ssMapping.java:810)
 at
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
ository.java:316)
 at
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
.java:602)
 at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
va:489)
 ... 24 more
NestedThrowables:
<4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: Field
"crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by field,
but this field is not a direct relation.
 at
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
y.map(RelationToManyInverseKeyFieldStrategy.java:123)
 at
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
va:781)
 at
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
...


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com]
Sent: Monday, April 02, 2007 12:42 PM
To: open-jpa-dev@incubator.apache.org
Subject: composite ID w/ another composite ID as a field

say i have Library, Book, and Page classes. a Library has many Books,
and a Book has many Pages. A Library's ID is it's name (simple). A
Book's ID is a composite of it's name and it's owning Library's name
(bidirectional relationship). A Page's ID is a composite of it's number
and it's owning Book's ID, a BookID.

so, the PageId class starts like:

public class PageId implements Serializable {
    private int number;
    private BookId book;

the error i'm getting is at runtime ...

<4|true|0.9.6-incubating>
org.apache.openjpa.persistence.ArgumentException: Field
"com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book"
as its mapped-by field, but this field is not a direct relation.

first, is what i'm trying to do even valid? i suspect it is not, and the
problem is that the fields of the ID class must be "simple" types  (i
believe the spec demands that). although, the error message is a little
confusing so i am not sure.

it occurs to me that another way to achieve this would be to add
bookName and libraryName fields to the Page class, and add a @PrePersist
method that populates them by calling book.getName() and
book.getLibrary().getName(). but again this is messy because that data
is already in the table because of the bidirectional relationship
between the objects.

as always, i'm open to "what are you an idiot?" responses if i am just
going about trying to define the Library, Book, Page relationship in an
obtuse manner.

classes attached.


________________________________

The fish are biting.
Get more visitors
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
>  on your site using Yahoo! Search Marketing.
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
> 

Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

RE: composite ID w/ another composite ID as a field

Posted by jpa_user <ko...@gmail.com>.
Hi,
I am using OpenJPA version 1.1.0. I have a scenario which is similar to the
example being discussed in this thread(Library,Book,Page) So I tried to run
the  example as being discussed in the thread and getting Null Pointer
Exception.Stack trace is below:
I want to know whether this is an issue to be fixed in JPA or am I doing
something wrong?

Exception:
16  domain  TRACE  [main] openjpa.Runtime - Setting the following properties
from
"file:/E:/Workspaces/CIS_JPA/jpa-composite-key/build/META-INF/persistence.xml"
into configuration: {java.ext.dirs=E:\IBM\WID61\jdk\jre\lib\ext,
openjpa.MetaDataFactory=jpa(Types=com.ibm.bookstore.Book;com.ibm.bookstore.BookId;com.ibm.bookstore.Library;com.ibm.bookstore.Page;com.ibm.bookstore.PageId),
openjpa.Id=domain, java.runtime.version=pwi32devifx-20070323 (ifix 117674:
SR4 + 116644 + 114941 + 116110 + 114881),
openjpa.ConnectionPassword=password-1, openjpa.BrokerFactory=jdbc,
user.country=US, file.separator=\, java.jcl.version=20070131,
openjpa.ConnectionDriverName=com.ibm.db2.jcc.DB2Driver, java.vm.version=2.3,
sun.java2d.fontpath=, line.separator=
, java.compiler=j9jit23, user.dir=E:\Workspaces\CIS_JPA\jpa-composite-key,
sun.io.unicode.encoding=UnicodeLittle, com.ibm.cpu.endian=little,
user.variant=, java.specification.name=Java Platform API Specification,
java.vm.specification.name=Java Virtual Machine Specification,
java.specification.vendor=Sun Microsystems Inc., path.separator=;,
sun.arch.data.model=32, ibm.signalhandling.sigchain=true, os.name=Windows
XP, sun.boot.library.path=E:\IBM\WID61\jdk\jre\bin, sun.jnu.encoding=Cp1252,
openjpa.ConnectionUserName=db2admin, os.version=5.1 build 2600 Service Pack
2, user.name=Administrator, awt.toolkit=sun.awt.windows.WToolkit,
ibm.signalhandling.rs=false, com.ibm.util.extralibs.properties=,
java.awt.fonts=, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment,
java.library.path=E:\IBM\WID61\jdk\jre\bin;.;E:\apacheant\ant\bin;E:\IBM\WID61\jdk\bin;C:\Program
Files\Common Files\NetSarang;C:\Program
Files\Edifecs\XEngine\Bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;E:\Program
Files\Rational\ClearCase\bin;E:\Program
Files\Rational\common;C:\SDP\6.0\runtimes\base_v6\java\bin;E:\PROGRA~1\IBM\SQLLIB\BIN;E:\PROGRA~1\IBM\SQLLIB\FUNCTION;E:\PROGRA~1\IBM\SQLLIB\SAMPLES\REPL;C:\Program
Files\Sun\MessageQueue3\bin;C:\Program Files\cvsnt;C:\Program
Files\IBM\WebSphere Transformation Extender
8.1\;E:\IBM\WBModeler61\WBModeler61\plugins\org.jawin_1.0.19\jawin.dll;E:\IBM\WBModeler61\CBM\plugins\org.jawin_1.0.19\jawin.dll;C:\WBModeler61\plugins\org.jawin_1.0.19\jawin.dll;E:\IBM\SQLLIBS\BIN;E:\IBM\SQLLIBS\FUNCTION;E:\IBM\SQLLIBS\SAMPLES\REPL;E:\apacheant\ant\bin;C:\jwsdp-1.1\jwsdp-shared\bin;C:\CVSNT;c:\maven-2.0.4\bin,
invokedviajava=, java.vm.specification.version=1.0, com.ibm.vm.bitmode=32,
com.ibm.oti.vm.library.version=23, user.timezone=, java.vm.info=J2RE 1.5.0
IBM J9 2.3 Windows XP x86-32 j9vmwi3223ifx-20070323 (JIT enabled)
J9VM - 20070322_12058_lHdSMR
JIT  - 20070109_1805ifx3_r8
GC   - WASIFIX_2007, ibm.system.encoding=Cp1252,
javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
sun.boot.class.path=E:\IBM\WID61\jdk\jre\lib\vm.jar;E:\IBM\WID61\jdk\jre\lib\core.jar;E:\IBM\WID61\jdk\jre\lib\charsets.jar;E:\IBM\WID61\jdk\jre\lib\graphics.jar;E:\IBM\WID61\jdk\jre\lib\security.jar;E:\IBM\WID61\jdk\jre\lib\ibmpkcs.jar;E:\IBM\WID61\jdk\jre\lib\ibmorb.jar;E:\IBM\WID61\jdk\jre\lib\ibmcfw.jar;E:\IBM\WID61\jdk\jre\lib\ibmorbapi.jar;E:\IBM\WID61\jdk\jre\lib\ibmjcefw.jar;E:\IBM\WID61\jdk\jre\lib\ibmjgssprovider.jar;E:\IBM\WID61\jdk\jre\lib\ibmjsseprovider2.jar;E:\IBM\WID61\jdk\jre\lib\ibmjaaslm.jar;E:\IBM\WID61\jdk\jre\lib\ibmjaasactivelm.jar;E:\IBM\WID61\jdk\jre\lib\ibmcertpathprovider.jar;E:\IBM\WID61\jdk\jre\lib\server.jar;E:\IBM\WID61\jdk\jre\lib\xml.jar,
openjpa.ConnectionURL=jdbc:db2://9.126.192.29:50001/JPA_MSG,
java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory,
java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition,
java.home=E:\IBM\WID61\jdk\jre,
java.class.path=E:\Workspaces\CIS_JPA\jpa-composite-key\build;E:\IBM\SQLLIB\java\sqlj.zip;E:\IBM\SQLLIB\java\Common.jar;E:\IBM\SQLLIB\java\db2java.zip;E:\IBM\SQLLIB\java\db2jcc.jar;E:\IBM\SQLLIB\java\db2jcc_license_cu.jar;E:\IBM\SQLLIB\java\db2policy.jar;E:\IBM\SQLLIB\java\db2qgjava.jar;E:\IBM\SQLLIB\java\db2umplugin.jar;E:\klp\Tech\JPA\apache-openjpa-1.1.0-binary\apache-openjpa-1.1.0\openjpa-1.1.0.jar;E:\klp\Tech\JPA\apache-openjpa-1.1.0-binary\apache-openjpa-1.1.0\lib\serp-1.13.1.jar;E:\klp\Tech\JPA\apache-openjpa-1.1.0-binary\apache-openjpa-1.1.0\lib\commons-collections-3.2.jar;E:\klp\Tech\JPA\apache-openjpa-1.1.0-binary\apache-openjpa-1.1.0\lib\commons-lang-2.1.jar;E:\klp\Tech\JPA\apache-openjpa-1.1.0-binary\apache-openjpa-1.1.0\lib\geronimo-jpa_3.0_spec-1.0.jar;E:\klp\Tech\JPA\apache-openjpa-1.1.0-binary\apache-openjpa-1.1.0\lib\geronimo-jta_1.1_spec-1.1.jar,
user.home=C:\Documents and Settings\Administrator,
com.ibm.oti.jcl.build=20070221_1314, java.specification.version=1.5,
os.arch=x86, java.awt.printerjob=sun.awt.windows.WPrinterJob,
java.vm.specification.vendor=Sun Microsystems Inc.,
com.ibm.oti.vm.bootstrap.library.path=E:\IBM\WID61\jdk\jre\bin,
java.fullversion=J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32
j9vmwi3223ifx-20070323 (JIT enabled)
J9VM - 20070322_12058_lHdSMR
JIT  - 20070109_1805ifx3_r8
GC   - WASIFIX_2007, os.encoding=UTF8, user.language=en,
jxe.lowest.romimage.version=9, java.vm.name=IBM J9 VM,
java.class.version=49.0, java.vendor.url=http://www.ibm.com/,
java.vendor=IBM Corporation, java.vm.vendor=IBM Corporation,
java.io.tmpdir=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\, java.version=1.5.0,
openjpa.Log=DefaultLevel=TRACE, Runtime=TRACE, Tool=TRACE,
com.ibm.oti.configuration=scar, file.encoding=Cp1252,
ibm.signalhandling.sigint=true, java.assistive=ON,
jxe.current.romimage.version=9}
110  domain  INFO   [main] openjpa.Runtime - Starting OpenJPA 1.1.0
110  domain  TRACE  [main] openjpa.Runtime - Properties: openjpa.AutoDetach: 
openjpa.MetaDataFactory:
jpa(Types=com.ibm.bookstore.Book;com.ibm.bookstore.BookId;com.ibm.bookstore.Library;com.ibm.bookstore.Page;com.ibm.bookstore.PageId)
openjpa.EntityManagerFactory: default
openjpa.ProxyManager: default
openjpa.jdbc.EagerFetchMode: parallel
openjpa.DataCache: false
openjpa.LockTimeout: -1
openjpa.Id: domain
openjpa.QueryCache: true
openjpa.ConnectionPassword: password-1
openjpa.BrokerImpl: default
openjpa.BrokerFactory: jdbc
openjpa.Compatibility: default
openjpa.FetchGroups: default
openjpa.ConnectionDriverName: com.ibm.db2.jcc.DB2Driver
openjpa.QueryCompilationCache: true
openjpa.DataCacheTimeout: -1
openjpa.NontransactionalWrite: true
openjpa.RetryClassRegistration: false
openjpa.jdbc.TransactionIsolation: default
openjpa.Multithreaded: false
openjpa.TransactionMode: local
openjpa.ConnectionRetainMode: on-demand
openjpa.AutoClear: datastore
openjpa.Sequence: table
openjpa.jdbc.Schemas: 
openjpa.WriteLockLevel: write
openjpa.MetaDataRepository: default
openjpa.DynamicDataStructs: false
openjpa.ConnectionUserName: db2admin
openjpa.RetainState: true
openjpa.Optimistic: true
openjpa.jdbc.ResultSetType: forward-only
openjpa.LockManager: version
openjpa.RestoreState: immutable
openjpa.jdbc.SynchronizeMappings: false
openjpa.RuntimeUnenhancedClasses: supported
openjpa.jdbc.FetchDirection: forward
openjpa.InverseManager: false
openjpa.jdbc.LRSSize: query
openjpa.ConnectionURL: jdbc:db2://9.126.192.29:50001/JPA_MSG
openjpa.jdbc.SQLFactory: default
openjpa.DataCacheManager: default
openjpa.MaxFetchDepth: -1
openjpa.NontransactionalRead: true
openjpa.jdbc.MappingDefaults: jpa
openjpa.ReadLockLevel: read
openjpa.ClassResolver: default
openjpa.FlushBeforeQueries: true
openjpa.FetchBatchSize: -1
openjpa.SavepointManager: in-mem
openjpa.ManagedRuntime: auto
openjpa.IgnoreChanges: false
openjpa.jdbc.SchemaFactory: dynamic
openjpa.ConnectionFactoryMode: local
openjpa.OrphanedKeyAction: log
openjpa.jdbc.SubclassFetchMode: join
openjpa.jdbc.UpdateManager: default
openjpa.Log: DefaultLevel=TRACE, Runtime=TRACE, Tool=TRACE
openjpa.jdbc.DriverDataSource: simple
openjpa.DetachState: loaded
110  domain  TRACE  [main] openjpa.Runtime - No cache marshaller found for
id org.apache.openjpa.conf.MetaDataCacheMaintenance.
219  domain  TRACE  [main] openjpa.MetaData - Using metadata factory
"org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@34723472".
266  domain  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
"org.apache.openjpa.jdbc.sql.DB2Dictionary".
985  domain  TRACE  [main] openjpa.jdbc.JDBC - catalogSeparator: .
catalogTerm: null
databaseProductName: DB2/NT
databaseProductVersion: SQL09050
driverName: IBM DB2 JDBC Universal Driver Architecture
driverVersion: 3.50.152
extraNameCharacters: @#
identifierQuoteString: "
numericFunctions:
ABS,ACOS,ASIN,ATAN,ATAN2,CEILING,COS,COT,DEGREES,EXP,FLOOR,LOG,LOG10,MOD,POWER,RADIANS,RAND,ROUND,SIGN,SIN,SQRT,TAN,TRUNCATE
procedureTerm: stored procedure
schemaTerm: schema
searchStringEscape: \
sqlKeywords:
AFTER,ALIAS,ALLOW,APPLICATION,ASSOCIATE,ASUTIME,AUDIT,AUX,AUXILIARY,BEFORE,BINARY,BUFFERPOOL,CACHE,CALL,CALLED,CAPTURE,CARDINALITY,CCSID,CLUSTER,COLLECTION,COLLID,COMMENT,CONCAT,CONDITION,CONTAINS,COUNT_BIG,CURRENT_LC_CTYPE,CURRENT_PATH,CURRENT_SERVER,CURRENT_TIMEZONE,CYCLE,DATA,DATABASE,DAYS,DB2GENERAL,DB2GENRL,DB2SQL,DBINFO,DEFAULTS,DEFINITION,DETERMINISTIC,DISALLOW,DO,DSNHATTR,DSSIZE,DYNAMIC,EACH,EDITPROC,ELSEIF,ENCODING,END-EXEC1,ERASE,EXCLUDING,EXIT,FENCED,FIELDPROC,FILE,FINAL,FREE,FUNCTION,GENERAL,GENERATED,GRAPHIC,HANDLER,HOLD,HOURS,IF,INCLUDING,INCREMENT,INDEX,INHERIT,INOUT,INTEGRITY,ISOBID,ITERATE,JAR,JAVA,LABEL,LC_CTYPE,LEAVE,LINKTYPE,LOCALE,LOCATOR,LOCATORS,LOCK,LOCKMAX,LOCKSIZE,LONG,LOOP,MAXVALUE,MICROSECOND,MICROSECONDS,MINUTES,MINVALUE,MODE,MODIFIES,MONTHS,NEW,NEW_TABLE,NOCACHE,NOCYCLE,NODENAME,NODENUMBER,NOMAXVALUE,NOMINVALUE,NOORDER,NULLS,NUMPARTS,OBID,OLD,OLD_TABLE,OPTIMIZATION,OPTIMIZE,OUT,OVERRIDING,PACKAGE,PARAMETER,PART,PARTITION,PATH,PIECESIZE,PLAN,PRIQTY,PROGRAM,PSID,QUERYNO,READS,RECOVERY,REFERENCING,RELEASE,RENAME,REPEAT,RESET,RESIGNAL,RESTART,RESULT,RESULT_SET_LOCATOR,RETURN,RETURNS,ROUTINE,ROW,RRN,RUN,SAVEPOINT,SCRATCHPAD,SECONDS,SECQTY,SECURITY,SENSITIVE,SIGNAL,SIMPLE,SOURCE,SPECIFIC,SQLID,STANDARD,START,STATIC,STAY,STOGROUP,STORES,STYLE,SUBPAGES,SYNONYM,SYSFUN,SYSIBM,SYSPROC,SYSTEM,TABLESPACE,TRIGGER,TYPE,UNDO,UNTIL,VALIDPROC,VARIABLE,VARIANT,VCAT,VOLUMES,WHILE,WLM,YEARS
stringFunctions:
ASCII,CHAR,CONCAT,DIFFERENCE,INSERT,LCASE,LEFT,LENGTH,LOCATE,LTRIM,REPEAT,REPLACE,RIGHT,RTRIM,SOUNDEX,SPACE,SUBSTRING,UCASE
systemFunctions: 
timeDateFunctions:
DAYNAME,DAYOFWEEK,DAYOFYEAR,HOUR,MINUTE,MONTH,MONTHNAME,QUARTER,SECOND,TIMESTAMPDIFF,WEEK,YEAR,CURDATE,CURTIME,NOW
url: jdbc:db2://9.126.192.29:50001/JPA_MSG
userName: db2admin
defaultTransactionIsolation: 2
driverMajorVersion: 3
driverMinorVersion: 50
maxBinaryLiteralLength: 4000
maxCatalogNameLength: 8
maxCharLiteralLength: 32672
maxColumnNameLength: 128
maxColumnsInGroupBy: 1012
maxColumnsInIndex: 16
maxColumnsInOrderBy: 1012
maxColumnsInSelect: 1012
maxColumnsInTable: 1012
maxConnections: 0
maxCursorNameLength: 128
maxIndexLength: 1024
maxProcedureNameLength: 128
maxRowSize: 32677
maxSchemaNameLength: 128
maxStatementLength: 2097152
maxStatements: 0
maxTableNameLength: 128
maxTablesInSelect: 0
maxUserNameLength: 30
isCatalogAtStart: true
isReadOnly: false
nullPlusNonNullIsNull: true
nullsAreSortedAtEnd: false
nullsAreSortedAtStart: false
nullsAreSortedHigh: true
nullsAreSortedLow: false
storesLowerCaseIdentifiers: false
storesLowerCaseQuotedIdentifiers: false
storesMixedCaseIdentifiers: false
storesMixedCaseQuotedIdentifiers: false
storesUpperCaseIdentifiers: true
storesUpperCaseQuotedIdentifiers: false
supportsAlterTableWithAddColumn: true
supportsAlterTableWithDropColumn: false
supportsANSI92EntryLevelSQL: true
supportsANSI92FullSQL: false
supportsANSI92IntermediateSQL: false
supportsCatalogsInDataManipulation: false
supportsCatalogsInIndexDefinitions: false
supportsCatalogsInPrivilegeDefinitions: false
supportsCatalogsInProcedureCalls: false
supportsCatalogsInTableDefinitions: false
supportsColumnAliasing: true
supportsConvert: false
supportsCoreSQLGrammar: true
supportsCorrelatedSubqueries: true
supportsDataDefinitionAndDataManipulationTransactions: true
supportsDataManipulationTransactionsOnly: false
supportsDifferentTableCorrelationNames: false
supportsExpressionsInOrderBy: true
supportsExtendedSQLGrammar: true
supportsFullOuterJoins: true
supportsGroupBy: true
supportsGroupByBeyondSelect: true
supportsGroupByUnrelated: true
supportsIntegrityEnhancementFacility: true
supportsLikeEscapeClause: true
supportsLimitedOuterJoins: true
supportsMinimumSQLGrammar: true
supportsMixedCaseIdentifiers: false
supportsMixedCaseQuotedIdentifiers: true
supportsMultipleResultSets: true
supportsMultipleTransactions: true
supportsNonNullableColumns: true
supportsOpenCursorsAcrossCommit: true
supportsOpenCursorsAcrossRollback: false
supportsOpenStatementsAcrossCommit: true
supportsOpenStatementsAcrossRollback: true
supportsOrderByUnrelated: true
supportsOuterJoins: true
supportsPositionedDelete: true
supportsPositionedUpdate: true
supportsSchemasInDataManipulation: true
supportsSchemasInIndexDefinitions: true
supportsSchemasInPrivilegeDefinitions: true
supportsSchemasInProcedureCalls: true
supportsSchemasInTableDefinitions: true
supportsSelectForUpdate: true
supportsStoredProcedures: true
supportsSubqueriesInComparisons: true
supportsSubqueriesInExists: true
supportsSubqueriesInIns: true
supportsSubqueriesInQuantifieds: true
supportsTableCorrelationNames: true
supportsTransactions: true
supportsUnion: true
supportsUnionAll: true
usesLocalFilePerTable: false
usesLocalFiles: false
allProceduresAreCallable: false
allTablesAreSelectable: false
dataDefinitionCausesTransactionCommit: false
dataDefinitionIgnoredInTransactions: false
doesMaxRowSizeIncludeBlobs: false
supportsBatchUpdates: true
1000  domain  TRACE  [main] openjpa.jdbc.JDBC - <t 1096171862, conn
420223244> [0 ms] close
1094  domain  TRACE  [main] openjpa.MetaData - Scanning resource
"META-INF/orm.xml" for persistent types.
1094  domain  TRACE  [main] openjpa.MetaData - parsePersistentTypeNames()
found [com.ibm.bookstore.Library, com.ibm.bookstore.Page,
com.ibm.bookstore.PageId, com.ibm.bookstore.Book, com.ibm.bookstore.BookId].
1094  domain  TRACE  [main] openjpa.MetaData - Found 5 classes with metadata
in 0 milliseconds.
1125  domain  INFO   [main] openjpa.Enhance - Creating subclass for "[class
com.ibm.bookstore.Library, class com.ibm.bookstore.Page, class
com.ibm.bookstore.PageId, class com.ibm.bookstore.Book, class
com.ibm.bookstore.BookId]". This means that your application will be less
efficient and will consume more memory than it would if you ran the OpenJPA
enhancer. Additionally, lazy loading will not be available for one-to-one
and many-to-one persistent attributes in types using field access; they will
be loaded eagerly instead.
1235  domain  TRACE  [main] openjpa.Runtime - No cache marshaller found for
id org.apache.openjpa.conf.MetaDataCacheMaintenance.
1235  domain  TRACE  [main] openjpa.MetaData - Using metadata factory
"org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@2120212".
1235  domain  TRACE  [main] openjpa.MetaData - Loading metadata for "class
com.ibm.bookstore.Library" under mode "[META]".
1235  domain  TRACE  [main] openjpa.MetaData - Scanning resource
"META-INF/orm.xml" for persistent types.
1235  domain  TRACE  [main] openjpa.MetaData - parsePersistentTypeNames()
found [com.ibm.bookstore.Library, com.ibm.bookstore.Page,
com.ibm.bookstore.PageId, com.ibm.bookstore.Book, com.ibm.bookstore.BookId].
1235  domain  TRACE  [main] openjpa.MetaData - Found 5 classes with metadata
in 0 milliseconds.
1313  domain  TRACE  [main] openjpa.MetaData - Parsing class
"com.ibm.bookstore.Library".
1313  domain  TRACE  [main] openjpa.MetaData - Parsing package
"com.ibm.bookstore.Library".
1391  domain  TRACE  [main] openjpa.MetaData - Generating default metadata
for type "com.ibm.bookstore.Library".
1391  domain  TRACE  [main] openjpa.MetaData - Using reflection for metadata
generation.
1422  domain  TRACE  [main] openjpa.MetaData - Set persistence-capable
superclass of "com.ibm.bookstore.Library" to "null".
1422  domain  TRACE  [main] openjpa.MetaData - Resolving metadata for
"com.ibm.bookstore.Library@1293176084".
1422  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Library@1293176084.books".
1422  domain  TRACE  [main] openjpa.MetaData - Loading metadata for "class
com.ibm.bookstore.Book" under mode "[META]".
1422  domain  TRACE  [main] openjpa.MetaData - Parsing class
"com.ibm.bookstore.Book".
1438  domain  TRACE  [main] openjpa.MetaData - Generating default metadata
for type "com.ibm.bookstore.Book".
1438  domain  TRACE  [main] openjpa.MetaData - Using reflection for metadata
generation.
1438  domain  TRACE  [main] openjpa.MetaData - Set persistence-capable
superclass of "com.ibm.bookstore.Book" to "null".
1453  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Library@1293176084.name".
1453  domain  TRACE  [main] openjpa.MetaData - Resolving metadata for
"com.ibm.bookstore.Book@2076343234".
1453  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@2076343234.library".
1453  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@2076343234.name".
1453  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@2076343234.pages".
1453  domain  TRACE  [main] openjpa.MetaData - Loading metadata for "class
com.ibm.bookstore.Page" under mode "[META]".
1453  domain  TRACE  [main] openjpa.MetaData - Parsing class
"com.ibm.bookstore.Page".
1485  domain  TRACE  [main] openjpa.MetaData - Generating default metadata
for type "com.ibm.bookstore.Page".
1485  domain  TRACE  [main] openjpa.MetaData - Using reflection for metadata
generation.
1485  domain  TRACE  [main] openjpa.MetaData - Set persistence-capable
superclass of "com.ibm.bookstore.Page" to "null".
1485  domain  TRACE  [main] openjpa.MetaData - Resolving metadata for
"com.ibm.bookstore.Page@1007959060".
1485  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Page@1007959060.book".
1485  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Page@1007959060.number".
1485  domain  TRACE  [main] openjpa.MetaData - Preparing mapping for
"com.ibm.bookstore.Library".
1500  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Library@1293176084.name".
1500  domain  TRACE  [main] openjpa.MetaData - 	"name" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy".
1500  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Library<discriminator>" has mapping strategy "none".
1516  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Library<version>" has mapping strategy "none".
1516  domain  TRACE  [main] openjpa.MetaData - Preparing mapping for
"com.ibm.bookstore.Book".
1516  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@2076343234.library".
1531  domain  TRACE  [main] openjpa.MetaData - 	"library" has mapping
strategy "org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy".
1531  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@2076343234.name".
1531  domain  TRACE  [main] openjpa.MetaData - 	"name" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy".
1531  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Book<discriminator>" has mapping strategy "none".
1531  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Book<version>" has mapping strategy "none".
1531  domain  TRACE  [main] openjpa.MetaData - Preparing mapping for
"com.ibm.bookstore.Page".
1531  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Page@1007959060.book".
1531  domain  TRACE  [main] openjpa.MetaData - 	"book" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy".
1531  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Page@1007959060.number".
1531  domain  TRACE  [main] openjpa.MetaData - 	"number" has mapping
strategy "org.apache.openjpa.jdbc.meta.strats.PrimitiveFieldStrategy".
1531  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Page<discriminator>" has mapping strategy "none".
1531  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Page<version>" has mapping strategy "none".
1531  domain  TRACE  [main] openjpa.MetaData - Resolving mapping for
"com.ibm.bookstore.Library@1293176084".
1531  domain  TRACE  [main] openjpa.MetaData - "com.ibm.bookstore.Library"
has mapping strategy "full".
1531  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Library@1293176084.books".
1547  domain  TRACE  [main] openjpa.MetaData - 	"books" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStrategy".
1547  domain  TRACE  [main] openjpa.MetaData - Resolving mapping for
"com.ibm.bookstore.Book@2076343234".
1547  domain  TRACE  [main] openjpa.MetaData - "com.ibm.bookstore.Book" has
mapping strategy "full".
1547  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@2076343234.pages".
1547  domain  TRACE  [main] openjpa.MetaData - 	"pages" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStrategy".
1547  domain  TRACE  [main] openjpa.MetaData - Resolving mapping for
"com.ibm.bookstore.Page@1007959060".
1547  domain  TRACE  [main] openjpa.MetaData - "com.ibm.bookstore.Page" has
mapping strategy "full".
1547  domain  TRACE  [main] openjpa.Enhance - Enhancing type "class
com.ibm.bookstore.Library".
1625  domain  TRACE  [main] openjpa.Runtime - No cache marshaller found for
id org.apache.openjpa.conf.MetaDataCacheMaintenance.
1625  domain  TRACE  [main] openjpa.MetaData - Using metadata factory
"org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@3ebe3ebe".
1625  domain  TRACE  [main] openjpa.MetaData - Loading metadata for "class
com.ibm.bookstore.Page" under mode "[META]".
1625  domain  TRACE  [main] openjpa.MetaData - Scanning resource
"META-INF/orm.xml" for persistent types.
1625  domain  TRACE  [main] openjpa.MetaData - parsePersistentTypeNames()
found [com.ibm.bookstore.Library, com.ibm.bookstore.Page,
com.ibm.bookstore.PageId, com.ibm.bookstore.Book, com.ibm.bookstore.BookId].
1625  domain  TRACE  [main] openjpa.MetaData - Found 5 classes with metadata
in 0 milliseconds.
1625  domain  TRACE  [main] openjpa.MetaData - Parsing class
"com.ibm.bookstore.Page".
1625  domain  TRACE  [main] openjpa.MetaData - Parsing package
"com.ibm.bookstore.Page".
1625  domain  TRACE  [main] openjpa.MetaData - Generating default metadata
for type "com.ibm.bookstore.Page".
1625  domain  TRACE  [main] openjpa.MetaData - Using reflection for metadata
generation.
1641  domain  TRACE  [main] openjpa.MetaData - Set persistence-capable
superclass of "com.ibm.bookstore.Page" to "null".
1641  domain  TRACE  [main] openjpa.MetaData - Loading metadata for "class
com.ibm.bookstore.Book" under mode "[META]".
1641  domain  TRACE  [main] openjpa.MetaData - Parsing class
"com.ibm.bookstore.Book".
1641  domain  TRACE  [main] openjpa.MetaData - Generating default metadata
for type "com.ibm.bookstore.Book".
1641  domain  TRACE  [main] openjpa.MetaData - Using reflection for metadata
generation.
1641  domain  TRACE  [main] openjpa.MetaData - Set persistence-capable
superclass of "com.ibm.bookstore.Book" to "null".
1641  domain  TRACE  [main] openjpa.MetaData - Loading metadata for "class
com.ibm.bookstore.Library" under mode "[META]".
1641  domain  TRACE  [main] openjpa.MetaData - Parsing class
"com.ibm.bookstore.Library".
1641  domain  TRACE  [main] openjpa.MetaData - Generating default metadata
for type "com.ibm.bookstore.Library".
1641  domain  TRACE  [main] openjpa.MetaData - Set persistence-capable
superclass of "com.ibm.bookstore.Library" to "null".
1641  domain  TRACE  [main] openjpa.MetaData - Resolving metadata for
"com.ibm.bookstore.Library@1836739962".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Library@1836739962.books".
1641  domain  TRACE  [main] openjpa.MetaData - Set persistence-capable
superclass of "com.ibm.bookstore.Book" to "null".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Library@1836739962.name".
1641  domain  TRACE  [main] openjpa.MetaData - Resolving metadata for
"com.ibm.bookstore.Book@614212764".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@614212764.library".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@614212764.name".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@614212764.pages".
1641  domain  TRACE  [main] openjpa.MetaData - Set persistence-capable
superclass of "com.ibm.bookstore.Page" to "null".
1641  domain  TRACE  [main] openjpa.MetaData - Resolving metadata for
"com.ibm.bookstore.Page@1667392354".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Page@1667392354.book".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Page@1667392354.number".
1641  domain  TRACE  [main] openjpa.MetaData - Preparing mapping for
"com.ibm.bookstore.Library".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Library@1836739962.name".
1641  domain  TRACE  [main] openjpa.MetaData - 	"name" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy".
1641  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Library<discriminator>" has mapping strategy "none".
1641  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Library<version>" has mapping strategy "none".
1641  domain  TRACE  [main] openjpa.MetaData - Preparing mapping for
"com.ibm.bookstore.Book".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@614212764.library".
1641  domain  TRACE  [main] openjpa.MetaData - 	"library" has mapping
strategy "org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy".
1641  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@614212764.name".
1656  domain  TRACE  [main] openjpa.MetaData - 	"name" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy".
1656  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Book<discriminator>" has mapping strategy "none".
1656  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Book<version>" has mapping strategy "none".
1656  domain  TRACE  [main] openjpa.MetaData - Preparing mapping for
"com.ibm.bookstore.Page".
1656  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Page@1667392354.book".
1656  domain  TRACE  [main] openjpa.MetaData - 	"book" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy".
1656  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Page@1667392354.number".
1656  domain  TRACE  [main] openjpa.MetaData - 	"number" has mapping
strategy "org.apache.openjpa.jdbc.meta.strats.PrimitiveFieldStrategy".
1656  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Page<discriminator>" has mapping strategy "none".
1656  domain  TRACE  [main] openjpa.MetaData -
"com.ibm.bookstore.Page<version>" has mapping strategy "none".
1656  domain  TRACE  [main] openjpa.MetaData - Resolving mapping for
"com.ibm.bookstore.Library@1836739962".
1656  domain  TRACE  [main] openjpa.MetaData - "com.ibm.bookstore.Library"
has mapping strategy "full".
1656  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Library@1836739962.books".
1656  domain  TRACE  [main] openjpa.MetaData - 	"books" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStrategy".
1656  domain  TRACE  [main] openjpa.MetaData - Resolving mapping for
"com.ibm.bookstore.Book@614212764".
1656  domain  TRACE  [main] openjpa.MetaData - "com.ibm.bookstore.Book" has
mapping strategy "full".
1656  domain  TRACE  [main] openjpa.MetaData - 	Resolving field
"com.ibm.bookstore.Book@614212764.pages".
1656  domain  TRACE  [main] openjpa.MetaData - 	"pages" has mapping strategy
"org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStrategy".
1656  domain  TRACE  [main] openjpa.MetaData - Resolving mapping for
"com.ibm.bookstore.Page@1667392354".
1656  domain  TRACE  [main] openjpa.MetaData - "com.ibm.bookstore.Page" has
mapping strategy "full".
1656  domain  TRACE  [main] openjpa.Enhance - Enhancing type "class
com.ibm.bookstore.Page".
1703  domain  TRACE  [main] openjpa.Runtime - No cache marshaller found for
id org.apache.openjpa.conf.MetaDataCacheMaintenance.
1703  domain  TRACE  [main] openjpa.MetaData - Using metadata factory
"org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@5ffa5ffa".
1703  domain  TRACE  [main] openjpa.MetaData - Loading metadata for "class
com.ibm.bookstore.PageId" under mode "[META]".
1703  domain  TRACE  [main] openjpa.MetaData - Scanning resource
"META-INF/orm.xml" for persistent types.
1703  domain  TRACE  [main] openjpa.MetaData - parsePersistentTypeNames()
found [com.ibm.bookstore.Library, com.ibm.bookstore.Page,
com.ibm.bookstore.PageId, com.ibm.bookstore.Book, com.ibm.bookstore.BookId].
1703  domain  TRACE  [main] openjpa.MetaData - Found 5 classes with metadata
in 0 milliseconds.
1703  domain  TRACE  [main] openjpa.MetaData - Parsing class
"com.ibm.bookstore.PageId".
1703  domain  TRACE  [main] openjpa.MetaData - Parsing package
"com.ibm.bookstore.PageId".
Exception in thread "main" <openjpa-1.1.0-r422266:657916 nonfatal general
error> org.apache.openjpa.persistence.PersistenceException: null
	at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:196)
	at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
	at com.ibm.client.test.CompositeKeyTest.main(CompositeKeyTest.java:20)
Caused by: java.lang.NullPointerException
	at
org.apache.openjpa.enhance.ManagedClassSubclasser.setDetachedState(ManagedClassSubclasser.java:299)
	at
org.apache.openjpa.enhance.ManagedClassSubclasser.configureMetaData(ManagedClassSubclasser.java:217)
	at
org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:139)
	at
org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:310)
	at
org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:228)
	at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:190)
	... 5 more


farble1670 wrote:
> 
> after doing some decompilation, the problem line is ...
> 
>         PageId pageid = (PageId)((ObjectId)obj).getId();
> 
> in the enhanced Page class. so, looking at PageId, it's not an instance of
> ObjectId. so, i am not sure what is supposed to be happening here. i
> assume that PageId is supposed to be enhanced in some way. decompiling it
> shows that is not the case.
> 
> ???
> 
> thanks.
> 
> jeff <je...@yahoo.com> wrote: okay, by chance i looked at the
> open jpa pom and saw that it calls out surefire 2.2 w/ some particular
> options. sure enough, that fixed the classpath problem.
> 
> however, i still get the exception w/ regard to ObjectId after making the
> changes you suggested ...
> 
> Caused by: java.lang.ClassCastException: org.apache.openjpa.util.ObjectId
>         at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
>         at
> org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:355)
>         at
> org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2382)
> 
> jeff  wrote: thanks pinaki,
> 
> after making those changes, on 0.9.6, i get:
> 
> Caused by: java.lang.ClassCastException: org.apache.openjpa.util.ObjectId
>         at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
>         at
> org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
>         at
> org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)
> 
> i built the trunk locally, and mvn installed it into my local repository.
> when i run against it, i get:
> 
> Caused by: java.lang.RuntimeException: There were errors initializing your
> configuration: org.apache.openjpa.lib.util.ParseException: Instantiation
> of plugin "QueryCompilationCache" with value "true" caused an error
> "java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
> org.apache.openjpa.util.CacheMap". The alias or class name may have been
> misspelled (as it closely matches the valid plugin alias "true"), or the
> class may not be available in the class path.  Valid aliases for this
> plugin are: [all, false, true]
> 
> followed by:
> 
> Caused by: java.lang.IllegalArgumentException:
> java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap
>         at serp.util.Strings.toClass(Strings.java:211)
>         at serp.util.Strings.toClass(Strings.java:140)
>         at
> org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:191)
> 
> are there known issues w/ 0.9.7? what i don't understand is that
> ...CacheMap is in the sample place, in the same JAR as w/ the 0.9.6
> dependency, just in my local repository.
> 
> also odd is that i only see the one info message during enhancement:
> 
>      [java] 1268  book  INFO   [main] openjpa.Tool - No targets were
> given.  Running on all classes in your persistent classes list, or all
> metadata files in classpath directories if you have not listed your
> persistent classes.  Use -help to display tool usage information.
> 
> no details are printed about the classes being enhanced. obviously this
> was working in version 0,9.6.
> 
> any ideas?
> 
> Pinaki Poddar 
>  wrote: Hello Jeff,
> 
> OpenJPA supports the cited example where Page using a composite ID which
> in turn refers to Book's composite ID. 
> 
> Book/Page/Library classes work with 
> a) openjpa-0.9.7 (do not know whether observed errors are due to usage
> of earlier 0.9.6 version)  
> b) following modifications in Page.book field (with a + sign)
> 
>     @Id
>     @Column(nullable = false)
>     @ManyToOne (cascade = CascadeType.ALL)
>  +   @JoinColumns({
>  +      @JoinColumn(name="book_library_LIBRARY_NAME",
> referencedColumnName="library_LIBRARY_NAME"),
>  +      @JoinColumn(name="book_BOOK_NAME",
> referencedColumnName="BOOK_NAME")
>     })
>     private Book book;
> 
> 
> where the JoinColumns specification refers to following schema (as per
> your Page/Book/Library class annotations):
> 
> mysql> desc book;
> +----------------------+--------------+------+-----+---------+-------+
> | Field                | Type         | Null | Key | Default | Extra |
> +----------------------+--------------+------+-----+---------+-------+
> | library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |       |
> | BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |       |
> +----------------------+--------------+------+-----+---------+-------+
> mysql> desc page;
> +---------------------------+--------------+------+-----+---------+-----
> --+
> | Field                     | Type         | Null | Key | Default |
> Extra |
> +---------------------------+--------------+------+-----+---------+-----
> --+
> | book_library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |
> |
> | book_BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |
> |
> | PAGE_NUMBER               | int(11)      | NO   | PRI | NULL    |
> |
> +---------------------------+--------------+------+-----+---------+-----
> --+
> 
> 
> Without explicitly naming the join columns, following error is
> generated:
> 
> Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
> org.apache.openjpa.persistence.ArgumentException: "crxxx.Page.book" does
> not supply a name for at least one declared column.  Since this mapping
> can involve multiple columns or uses constant joins, each column must
> give either its name or a non-constant target.
>  at
> org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
> a:1372)
>  at
> org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
> 86)
>  at
> org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
> va:948)
>  at
> org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
> fo.java:101)
>  at
> org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
> eldStrategy.java:144)
>  at
> org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
> 117)
>  at
> org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
> ntimeStrategyInstaller.java:77)
>  at
> org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
> va:435)
>  at
> org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
>  at
> org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
> ssMapping.java:810)
>  at
> org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
> ository.java:316)
>  at
> org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
> .java:602)
>  at
> org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
> va:489)
>  ... 24 more
> NestedThrowables:
> <4|true|0.9.7-incubating-SNAPSHOT>
> org.apache.openjpa.persistence.ArgumentException: Field
> "crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by field,
> but this field is not a direct relation.
>  at
> org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
> y.map(RelationToManyInverseKeyFieldStrategy.java:123)
>  at
> org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
> ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
>  at
> org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
> 117)
>  at
> org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
> ntimeStrategyInstaller.java:77)
>  at
> org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
> va:435)
>  at
> org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
>  at
> org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
> va:781)
>  at
> org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
> ...
> 
> 
> Pinaki Poddar
> BEA Systems
> 415.402.7317  
> 
> 
> -----Original Message-----
> From: jeff [mailto:jeffrey.blattman@yahoo.com] 
> Sent: Monday, April 02, 2007 12:42 PM
> To: open-jpa-dev@incubator.apache.org
> Subject: composite ID w/ another composite ID as a field
> 
> say i have Library, Book, and Page classes. a Library has many Books,
> and a Book has many Pages. A Library's ID is it's name (simple). A
> Book's ID is a composite of it's name and it's owning Library's name
> (bidirectional relationship). A Page's ID is a composite of it's number
> and it's owning Book's ID, a BookID.
> 
> so, the PageId class starts like:
> 
> public class PageId implements Serializable {
>     private int number;
>     private BookId book;
> 
> the error i'm getting is at runtime ...
> 
> <4|true|0.9.6-incubating>
> org.apache.openjpa.persistence.ArgumentException: Field
> "com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book"
> as its mapped-by field, but this field is not a direct relation.
> 
> first, is what i'm trying to do even valid? i suspect it is not, and the
> problem is that the fields of the ID class must be "simple" types  (i
> believe the spec demands that). although, the error message is a little
> confusing so i am not sure.
> 
> it occurs to me that another way to achieve this would be to add
> bookName and libraryName fields to the Page class, and add a @PrePersist
> method that populates them by calling book.getName() and
> book.getLibrary().getName(). but again this is messy because that data
> is already in the table because of the bidirectional relationship
> between the objects.
> 
> as always, i'm open to "what are you an idiot?" responses if i am just
> going about trying to define the Library, Book, Page relationship in an
> obtuse manner.
> 
> classes attached.
> 
> 
> ________________________________
> 
> The fish are biting.
> Get more visitors
> sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
>>  on your site using Yahoo! Search Marketing.
> sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
>> 
> 
> Notice:  This email message, together with any attachments, may contain
> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> entities,  that may be confidential,  proprietary,  copyrighted  and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this by
> email and then delete it.
> 
>  
> ---------------------------------
> Need Mail bonding?
> Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
> 
> 
>  
> ---------------------------------
> Don't be flakey. Get Yahoo! Mail for Mobile and 
> always stay connected to friends.
> 
>  
> ---------------------------------
> It's here! Your new message!
> Get new email alerts with the free Yahoo! Toolbar.
> 
http://n2.nabble.com/file/n535474/compositeKey_forum.zip
compositeKey_forum.zip 
-- 
View this message in context: http://n2.nabble.com/composite-ID-w--another-composite-ID-as-a-field-tp213033p535474.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


RE: composite ID w/ another composite ID as a field

Posted by jeff <je...@yahoo.com>.
after doing some decompilation, the problem line is ...

        PageId pageid = (PageId)((ObjectId)obj).getId();

in the enhanced Page class. so, looking at PageId, it's not an instance of ObjectId. so, i am not sure what is supposed to be happening here. i assume that PageId is supposed to be enhanced in some way. decompiling it shows that is not the case.

???

thanks.

jeff <je...@yahoo.com> wrote: okay, by chance i looked at the open jpa pom and saw that it calls out surefire 2.2 w/ some particular options. sure enough, that fixed the classpath problem.

however, i still get the exception w/ regard to ObjectId after making the changes you suggested ...

Caused by: java.lang.ClassCastException: org.apache.openjpa.util.ObjectId
        at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
        at org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:355)
        at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2382)

jeff  wrote: thanks pinaki,

after making those changes, on 0.9.6, i get:

Caused by: java.lang.ClassCastException: org.apache.openjpa.util.ObjectId
        at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
        at org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
        at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)

i built the trunk locally, and mvn installed it into my local repository. when i run against it, i get:

Caused by: java.lang.RuntimeException: There were errors initializing your configuration: org.apache.openjpa.lib.util.ParseException: Instantiation of plugin "QueryCompilationCache" with value "true" caused an error "java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap". The alias or class name may have been misspelled (as it closely matches the valid plugin alias "true"), or the class may not be available in the class path.  Valid aliases for this plugin are: [all, false, true]

followed by:

Caused by: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap
        at serp.util.Strings.toClass(Strings.java:211)
        at serp.util.Strings.toClass(Strings.java:140)
        at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:191)

are there known issues w/ 0.9.7? what i don't understand is that ...CacheMap is in the sample place, in the same JAR as w/ the 0.9.6 dependency, just in my local repository.

also odd is that i only see the one info message during enhancement:

     [java] 1268  book  INFO   [main] openjpa.Tool - No targets were given.  Running on all classes in your persistent classes list, or all metadata files in classpath directories if you have not listed your persistent classes.  Use -help to display tool usage information.

no details are printed about the classes being enhanced. obviously this was working in version 0,9.6.

any ideas?

Pinaki Poddar 
 wrote: Hello Jeff,

OpenJPA supports the cited example where Page using a composite ID which
in turn refers to Book's composite ID. 

Book/Page/Library classes work with 
a) openjpa-0.9.7 (do not know whether observed errors are due to usage
of earlier 0.9.6 version)  
b) following modifications in Page.book field (with a + sign)

    @Id
    @Column(nullable = false)
    @ManyToOne (cascade = CascadeType.ALL)
 +   @JoinColumns({
 +      @JoinColumn(name="book_library_LIBRARY_NAME",
referencedColumnName="library_LIBRARY_NAME"),
 +      @JoinColumn(name="book_BOOK_NAME",
referencedColumnName="BOOK_NAME")
    })
    private Book book;


where the JoinColumns specification refers to following schema (as per
your Page/Book/Library class annotations):

mysql> desc book;
+----------------------+--------------+------+-----+---------+-------+
| Field                | Type         | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+---------+-------+
| library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |       |
| BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |       |
+----------------------+--------------+------+-----+---------+-------+
mysql> desc page;
+---------------------------+--------------+------+-----+---------+-----
--+
| Field                     | Type         | Null | Key | Default |
Extra |
+---------------------------+--------------+------+-----+---------+-----
--+
| book_library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |
|
| book_BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |
|
| PAGE_NUMBER               | int(11)      | NO   | PRI | NULL    |
|
+---------------------------+--------------+------+-----+---------+-----
--+


Without explicitly naming the join columns, following error is
generated:

Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: "crxxx.Page.book" does
not supply a name for at least one declared column.  Since this mapping
can involve multiple columns or uses constant joins, each column must
give either its name or a non-constant target.
 at
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
a:1372)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
86)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
va:948)
 at
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
fo.java:101)
 at
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
eldStrategy.java:144)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
ssMapping.java:810)
 at
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
ository.java:316)
 at
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
.java:602)
 at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
va:489)
 ... 24 more
NestedThrowables:
<4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: Field
"crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by field,
but this field is not a direct relation.
 at
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
y.map(RelationToManyInverseKeyFieldStrategy.java:123)
 at
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
va:781)
 at
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
...


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Monday, April 02, 2007 12:42 PM
To: open-jpa-dev@incubator.apache.org
Subject: composite ID w/ another composite ID as a field

say i have Library, Book, and Page classes. a Library has many Books,
and a Book has many Pages. A Library's ID is it's name (simple). A
Book's ID is a composite of it's name and it's owning Library's name
(bidirectional relationship). A Page's ID is a composite of it's number
and it's owning Book's ID, a BookID.

so, the PageId class starts like:

public class PageId implements Serializable {
    private int number;
    private BookId book;

the error i'm getting is at runtime ...

<4|true|0.9.6-incubating>
org.apache.openjpa.persistence.ArgumentException: Field
"com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book"
as its mapped-by field, but this field is not a direct relation.

first, is what i'm trying to do even valid? i suspect it is not, and the
problem is that the fields of the ID class must be "simple" types  (i
believe the spec demands that). although, the error message is a little
confusing so i am not sure.

it occurs to me that another way to achieve this would be to add
bookName and libraryName fields to the Page class, and add a @PrePersist
method that populates them by calling book.getName() and
book.getLibrary().getName(). but again this is messy because that data
is already in the table because of the bidirectional relationship
between the objects.

as always, i'm open to "what are you an idiot?" responses if i am just
going about trying to define the Library, Book, Page relationship in an
obtuse manner.

classes attached.


________________________________

The fish are biting.
Get more visitors
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
>  on your site using Yahoo! Search Marketing.
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.


 
---------------------------------
Don't be flakey. Get Yahoo! Mail for Mobile and 
always stay connected to friends.

 
---------------------------------
It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.

RE: composite ID w/ another composite ID as a field

Posted by jeff <je...@yahoo.com>.
okay, by chance i looked at the open jpa pom and saw that it calls out surefire 2.2 w/ some particular options. sure enough, that fixed the classpath problem.

however, i still get the exception w/ regard to ObjectId after making the changes you suggested ...

Caused by: java.lang.ClassCastException: org.apache.openjpa.util.ObjectId
        at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
        at org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:355)
        at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2382)

jeff <je...@yahoo.com> wrote: thanks pinaki,

after making those changes, on 0.9.6, i get:

Caused by: java.lang.ClassCastException: org.apache.openjpa.util.ObjectId
        at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
        at org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
        at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)

i built the trunk locally, and mvn installed it into my local repository. when i run against it, i get:

Caused by: java.lang.RuntimeException: There were errors initializing your configuration: org.apache.openjpa.lib.util.ParseException: Instantiation of plugin "QueryCompilationCache" with value "true" caused an error "java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap". The alias or class name may have been misspelled (as it closely matches the valid plugin alias "true"), or the class may not be available in the class path.  Valid aliases for this plugin are: [all, false, true]

followed by:

Caused by: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap
        at serp.util.Strings.toClass(Strings.java:211)
        at serp.util.Strings.toClass(Strings.java:140)
        at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:191)

are there known issues w/ 0.9.7? what i don't understand is that ...CacheMap is in the sample place, in the same JAR as w/ the 0.9.6 dependency, just in my local repository.

also odd is that i only see the one info message during enhancement:

     [java] 1268  book  INFO   [main] openjpa.Tool - No targets were given.  Running on all classes in your persistent classes list, or all metadata files in classpath directories if you have not listed your persistent classes.  Use -help to display tool usage information.

no details are printed about the classes being enhanced. obviously this was working in version 0,9.6.

any ideas?

Pinaki Poddar 
 wrote: Hello Jeff,

OpenJPA supports the cited example where Page using a composite ID which
in turn refers to Book's composite ID. 

Book/Page/Library classes work with 
a) openjpa-0.9.7 (do not know whether observed errors are due to usage
of earlier 0.9.6 version)  
b) following modifications in Page.book field (with a + sign)

    @Id
    @Column(nullable = false)
    @ManyToOne (cascade = CascadeType.ALL)
 +   @JoinColumns({
 +      @JoinColumn(name="book_library_LIBRARY_NAME",
referencedColumnName="library_LIBRARY_NAME"),
 +      @JoinColumn(name="book_BOOK_NAME",
referencedColumnName="BOOK_NAME")
    })
    private Book book;


where the JoinColumns specification refers to following schema (as per
your Page/Book/Library class annotations):

mysql> desc book;
+----------------------+--------------+------+-----+---------+-------+
| Field                | Type         | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+---------+-------+
| library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |       |
| BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |       |
+----------------------+--------------+------+-----+---------+-------+
mysql> desc page;
+---------------------------+--------------+------+-----+---------+-----
--+
| Field                     | Type         | Null | Key | Default |
Extra |
+---------------------------+--------------+------+-----+---------+-----
--+
| book_library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |
|
| book_BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |
|
| PAGE_NUMBER               | int(11)      | NO   | PRI | NULL    |
|
+---------------------------+--------------+------+-----+---------+-----
--+


Without explicitly naming the join columns, following error is
generated:

Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: "crxxx.Page.book" does
not supply a name for at least one declared column.  Since this mapping
can involve multiple columns or uses constant joins, each column must
give either its name or a non-constant target.
 at
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
a:1372)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
86)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
va:948)
 at
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
fo.java:101)
 at
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
eldStrategy.java:144)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
ssMapping.java:810)
 at
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
ository.java:316)
 at
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
.java:602)
 at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
va:489)
 ... 24 more
NestedThrowables:
<4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: Field
"crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by field,
but this field is not a direct relation.
 at
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
y.map(RelationToManyInverseKeyFieldStrategy.java:123)
 at
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
va:781)
 at
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
...


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Monday, April 02, 2007 12:42 PM
To: open-jpa-dev@incubator.apache.org
Subject: composite ID w/ another composite ID as a field

say i have Library, Book, and Page classes. a Library has many Books,
and a Book has many Pages. A Library's ID is it's name (simple). A
Book's ID is a composite of it's name and it's owning Library's name
(bidirectional relationship). A Page's ID is a composite of it's number
and it's owning Book's ID, a BookID.

so, the PageId class starts like:

public class PageId implements Serializable {
    private int number;
    private BookId book;

the error i'm getting is at runtime ...

<4|true|0.9.6-incubating>
org.apache.openjpa.persistence.ArgumentException: Field
"com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book"
as its mapped-by field, but this field is not a direct relation.

first, is what i'm trying to do even valid? i suspect it is not, and the
problem is that the fields of the ID class must be "simple" types  (i
believe the spec demands that). although, the error message is a little
confusing so i am not sure.

it occurs to me that another way to achieve this would be to add
bookName and libraryName fields to the Page class, and add a @PrePersist
method that populates them by calling book.getName() and
book.getLibrary().getName(). but again this is messy because that data
is already in the table because of the bidirectional relationship
between the objects.

as always, i'm open to "what are you an idiot?" responses if i am just
going about trying to define the Library, Book, Page relationship in an
obtuse manner.

classes attached.


________________________________

The fish are biting.
Get more visitors
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
>  on your site using Yahoo! Search Marketing.
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.


 
---------------------------------
Don't be flakey. Get Yahoo! Mail for Mobile and 
always stay connected to friends.

RE: composite ID w/ another composite ID as a field

Posted by jeff <je...@yahoo.com>.
thanks pinaki,

after making those changes, on 0.9.6, i get:

Caused by: java.lang.ClassCastException: org.apache.openjpa.util.ObjectId
        at com.mycompany.book.Page.pcCopyKeyFieldsToObjectId(Page.java)
        at org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:383)
        at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2349)

i built the trunk locally, and mvn installed it into my local repository. when i run against it, i get:

Caused by: java.lang.RuntimeException: There were errors initializing your configuration: org.apache.openjpa.lib.util.ParseException: Instantiation of plugin "QueryCompilationCache" with value "true" caused an error "java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap". The alias or class name may have been misspelled (as it closely matches the valid plugin alias "true"), or the class may not be available in the class path.  Valid aliases for this plugin are: [all, false, true]

followed by:

Caused by: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap
        at serp.util.Strings.toClass(Strings.java:211)
        at serp.util.Strings.toClass(Strings.java:140)
        at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:191)

are there known issues w/ 0.9.7? what i don't understand is that ...CacheMap is in the sample place, in the same JAR as w/ the 0.9.6 dependency, just in my local repository.

also odd is that i only see the one info message during enhancement:

     [java] 1268  book  INFO   [main] openjpa.Tool - No targets were given.  Running on all classes in your persistent classes list, or all metadata files in classpath directories if you have not listed your persistent classes.  Use -help to display tool usage information.

no details are printed about the classes being enhanced. obviously this was working in version 0,9.6.

any ideas?

Pinaki Poddar <pp...@bea.com> wrote: Hello Jeff,

OpenJPA supports the cited example where Page using a composite ID which
in turn refers to Book's composite ID. 

Book/Page/Library classes work with 
a) openjpa-0.9.7 (do not know whether observed errors are due to usage
of earlier 0.9.6 version)  
b) following modifications in Page.book field (with a + sign)

    @Id
    @Column(nullable = false)
    @ManyToOne (cascade = CascadeType.ALL)
 +   @JoinColumns({
 +      @JoinColumn(name="book_library_LIBRARY_NAME",
referencedColumnName="library_LIBRARY_NAME"),
 +      @JoinColumn(name="book_BOOK_NAME",
referencedColumnName="BOOK_NAME")
    })
    private Book book;


where the JoinColumns specification refers to following schema (as per
your Page/Book/Library class annotations):

mysql> desc book;
+----------------------+--------------+------+-----+---------+-------+
| Field                | Type         | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+---------+-------+
| library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |       |
| BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |       |
+----------------------+--------------+------+-----+---------+-------+
mysql> desc page;
+---------------------------+--------------+------+-----+---------+-----
--+
| Field                     | Type         | Null | Key | Default |
Extra |
+---------------------------+--------------+------+-----+---------+-----
--+
| book_library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |
|
| book_BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |
|
| PAGE_NUMBER               | int(11)      | NO   | PRI | NULL    |
|
+---------------------------+--------------+------+-----+---------+-----
--+


Without explicitly naming the join columns, following error is
generated:

Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: "crxxx.Page.book" does
not supply a name for at least one declared column.  Since this mapping
can involve multiple columns or uses constant joins, each column must
give either its name or a non-constant target.
 at
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
a:1372)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
86)
 at
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
va:948)
 at
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
fo.java:101)
 at
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
eldStrategy.java:144)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
ssMapping.java:810)
 at
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
ository.java:316)
 at
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
.java:602)
 at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
va:489)
 ... 24 more
NestedThrowables:
<4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: Field
"crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by field,
but this field is not a direct relation.
 at
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
y.map(RelationToManyInverseKeyFieldStrategy.java:123)
 at
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
 at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
 at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
va:781)
 at
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
...


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Monday, April 02, 2007 12:42 PM
To: open-jpa-dev@incubator.apache.org
Subject: composite ID w/ another composite ID as a field

say i have Library, Book, and Page classes. a Library has many Books,
and a Book has many Pages. A Library's ID is it's name (simple). A
Book's ID is a composite of it's name and it's owning Library's name
(bidirectional relationship). A Page's ID is a composite of it's number
and it's owning Book's ID, a BookID.

so, the PageId class starts like:

public class PageId implements Serializable {
    private int number;
    private BookId book;

the error i'm getting is at runtime ...

<4|true|0.9.6-incubating>
org.apache.openjpa.persistence.ArgumentException: Field
"com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book"
as its mapped-by field, but this field is not a direct relation.

first, is what i'm trying to do even valid? i suspect it is not, and the
problem is that the fields of the ID class must be "simple" types  (i
believe the spec demands that). although, the error message is a little
confusing so i am not sure.

it occurs to me that another way to achieve this would be to add
bookName and libraryName fields to the Page class, and add a @PrePersist
method that populates them by calling book.getName() and
book.getLibrary().getName(). but again this is messy because that data
is already in the table because of the bidirectional relationship
between the objects.

as always, i'm open to "what are you an idiot?" responses if i am just
going about trying to define the Library, Book, Page relationship in an
obtuse manner.

classes attached.


________________________________

The fish are biting.
Get more visitors
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
>  on your site using Yahoo! Search Marketing.
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.

RE: composite ID w/ another composite ID as a field

Posted by Pinaki Poddar <pp...@bea.com>.
Hello Jeff,

OpenJPA supports the cited example where Page using a composite ID which
in turn refers to Book's composite ID. 

Book/Page/Library classes work with 
a) openjpa-0.9.7 (do not know whether observed errors are due to usage
of earlier 0.9.6 version)  
b) following modifications in Page.book field (with a + sign)

    @Id
    @Column(nullable = false)
    @ManyToOne (cascade = CascadeType.ALL)
 +   @JoinColumns({
 +      @JoinColumn(name="book_library_LIBRARY_NAME",
referencedColumnName="library_LIBRARY_NAME"),
 +      @JoinColumn(name="book_BOOK_NAME",
referencedColumnName="BOOK_NAME")
    })
    private Book book;


where the JoinColumns specification refers to following schema (as per
your Page/Book/Library class annotations):

mysql> desc book;
+----------------------+--------------+------+-----+---------+-------+
| Field                | Type         | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+---------+-------+
| library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |       |
| BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |       |
+----------------------+--------------+------+-----+---------+-------+
mysql> desc page;
+---------------------------+--------------+------+-----+---------+-----
--+
| Field                     | Type         | Null | Key | Default |
Extra |
+---------------------------+--------------+------+-----+---------+-----
--+
| book_library_LIBRARY_NAME | varchar(255) | NO   | PRI | NULL    |
|
| book_BOOK_NAME            | varchar(255) | NO   | PRI | NULL    |
|
| PAGE_NUMBER               | int(11)      | NO   | PRI | NULL    |
|
+---------------------------+--------------+------+-----+---------+-----
--+


Without explicitly naming the join columns, following error is
generated:

Caused by: <4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: "crxxx.Page.book" does
not supply a name for at least one declared column.  Since this mapping
can involve multiple columns or uses constant joins, each column must
give either its name or a non-constant target.
	at
org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav
a:1372)
	at
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11
86)
	at
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
va:948)
	at
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn
fo.java:101)
	at
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
eldStrategy.java:144)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
	at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
	at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla
ssMapping.java:810)
	at
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep
ository.java:316)
	at
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository
.java:602)
	at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
va:489)
	... 24 more
NestedThrowables:
<4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: Field
"crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by field,
but this field is not a direct relation.
	at
org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg
y.map(RelationToManyInverseKeyFieldStrategy.java:123)
	at
org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr
ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
117)
	at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:77)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:435)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
	at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
va:781)
	at
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
...


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: jeff [mailto:jeffrey.blattman@yahoo.com] 
Sent: Monday, April 02, 2007 12:42 PM
To: open-jpa-dev@incubator.apache.org
Subject: composite ID w/ another composite ID as a field

say i have Library, Book, and Page classes. a Library has many Books,
and a Book has many Pages. A Library's ID is it's name (simple). A
Book's ID is a composite of it's name and it's owning Library's name
(bidirectional relationship). A Page's ID is a composite of it's number
and it's owning Book's ID, a BookID.

so, the PageId class starts like:

public class PageId implements Serializable {
    private int number;
    private BookId book;

the error i'm getting is at runtime ...

<4|true|0.9.6-incubating>
org.apache.openjpa.persistence.ArgumentException: Field
"com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book"
as its mapped-by field, but this field is not a direct relation.

first, is what i'm trying to do even valid? i suspect it is not, and the
problem is that the fields of the ID class must be "simple" types  (i
believe the spec demands that). although, the error message is a little
confusing so i am not sure.

it occurs to me that another way to achieve this would be to add
bookName and libraryName fields to the Page class, and add a @PrePersist
method that populates them by calling book.getName() and
book.getLibrary().getName(). but again this is messy because that data
is already in the table because of the bidirectional relationship
between the objects.

as always, i'm open to "what are you an idiot?" responses if i am just
going about trying to define the Library, Book, Page relationship in an
obtuse manner.

classes attached.


________________________________

The fish are biting.
Get more visitors
<http://us.rd.yahoo.com/evt=49679/*http://searchmarketing.yahoo.com/arp/
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
>  on your site using Yahoo! Search Marketing.
<http://us.rd.yahoo.com/evt=49679/*http://searchmarketing.yahoo.com/arp/
sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50
> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

Re: composite ID w/ another composite ID as a field

Posted by jeff <je...@yahoo.com>.
hi craig, thanks ...

your suggestion would imply that that BookId can be converted to and from a String object, right? i checked the spec, and i expected to find a requirement to have a toString() method and a string constructor that can work in unison to this end, but it's not there. maybe i am still thinking JDO.

anyway, i did try that, 

public class PageId implements Serializable {
    private int number;
    private String book;

and i get: 

Caused by: <4|true|0.9.6-incubating> org.apache.openjpa.persistence.ArgumentException: The id class specified by type "class com.mycompany.book.Page" does not match the primary key fields of the class.  Make sure your identity class has the same primary keys as your persistent type, that the access types are the same, and if you are getting this error at runtime, that you have your persistent class since last compiling your identity class.
FailedObject: book [java.lang.String]

any ideas?

Craig L Russell <Cr...@Sun.COM> wrote: Hi Jeff,

The pattern you use for Book/Library is
> public class BookId implements Serializable {
>     private String name;
>     private String library;

The pattern you use for Page/Book is
> public class PageId implements Serializable {
>     private int number;
>     private BookId book;

Have you tried

> public class PageId implements Serializable {
>     private int number;
>     private String book;

Craig

On Apr 2, 2007, at 10:41 AM, jeff wrote:

> say i have Library, Book, and Page classes. a Library has many  
> Books, and a Book has many Pages. A Library's ID is it's name  
> (simple). A Book's ID is a composite of it's name and it's owning  
> Library's name (bidirectional relationship). A Page's ID is a  
> composite of it's number and it's owning Book's ID, a BookID.
>
> so, the PageId class starts like:
>
> public class PageId implements Serializable {
>     private int number;
>     private BookId book;
>
> the error i'm getting is at runtime ...
>
> <4|true|0.9.6-incubating>  
> org.apache.openjpa.persistence.ArgumentException: Field  
> "com.mycompany.book.Book.pages" declares  
> "com.mycompany.book.Page.book" as its mapped-by field, but this  
> field is not a direct relation.
>
> first, is what i'm trying to do even valid? i suspect it is not,  
> and the problem is that the fields of the ID class must be "simple"  
> types  (i believe the spec demands that). although, the error  
> message is a little confusing so i am not sure.
>
> it occurs to me that another way to achieve this would be to add  
> bookName and libraryName fields to the Page class, and add a  
> @PrePersist method that populates them by calling book.getName()  
> and book.getLibrary().getName(). but again this is messy because  
> that data is already in the table because of the bidirectional  
> relationship between the objects.
>
> as always, i'm open to "what are you an idiot?" responses if i am  
> just going about trying to define the Library, Book, Page  
> relationship in an obtuse manner.
>
> classes attached.
>
> The fish are biting.
> Get more visitors on your site using Yahoo! Search Marketing.
> package com.mycompany.book;
>
> import java.io.Serializable;
> import java.util.HashSet;
> import java.util.Set;
> import javax.persistence.CascadeType;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.IdClass;
> import javax.persistence.ManyToOne;
> import javax.persistence.OneToMany;
> import javax.xml.bind.annotation.XmlAttribute;
> import javax.xml.bind.annotation.XmlElement;
>
> @IdClass(com.mycompany.book.BookId.class)
> @Entity
> public class Book implements Serializable {
>     @Id
>     @Column(
>         name="BOOK_NAME",
>         nullable = false
>     )
>     @XmlAttribute (required = true)
>     private String name;
>
>     @OneToMany(
>         cascade = CascadeType.ALL,
>         mappedBy = "book"
>     )
>     @XmlElement (name = "page")
>     private Set
 pages = new HashSet
();
>
>     @Id
>     @Column(
>         nullable = false
>     )
>     @ManyToOne (
>       cascade = CascadeType.ALL
>     )
>     private Library library;
>
>     public String getName() {
>         return name;
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public Page getPage(int n) {
>         for (Page p: pages) {
>             if (p.getNumber() == n) {
>                 return p;
>             }
>         }
>
>         return null;
>     }
>
>     public void putPage(Page p) {
>         p.setBook(this);
>         pages.add(p);
>     }
>
>     public boolean equals(Object o) {
>         if (!(o instanceof Book)) {
>             return false;
>         }
>
>         Book other = (Book)o;
>
>         if (!getName().equals(other.getName())) {
>             return false;
>         }
>
>         return true;
>     }
>
>     public int hashCode() {
>         return getName().hashCode();
>     }
>
>     public Library getLibrary() {
>         return library;
>     }
>
>     public void setLibrary(Library library) {
>         this.library = library;
>     }
>
> }
> package com.mycompany.book;
>
> import java.io.Serializable;
> import javax.xml.bind.annotation.XmlTransient;
>
> @XmlTransient
> public class BookId implements Serializable {
>     private String name;
>     private String library;
>
>
>     public boolean equals(Object o) {
>         if (!(o instanceof BookId)) {
>             return false;
>         }
>
>         BookId other = (BookId)o;
>
>         if (!(getName().equals(other.getName()))) {
>             return false;
>         }
>
>         if (!getLibrary().equals(other.getLibrary())) {
>             return false;
>         }
>
>         return true;
>     }
>
>     public int hashCode() {
>         return getName().hashCode() * getLibrary().hashCode();
>     }
>
>     public String getName() {
>         return name;
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public String getLibrary() {
>         return library;
>     }
>
>     public void setLibrary(String library) {
>         this.library = library;
>     }
> }
> package com.mycompany.book;
>
> import java.io.Serializable;
> import java.util.HashSet;
> import java.util.Set;
> import javax.persistence.CascadeType;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.OneToMany;
> import javax.xml.bind.annotation.XmlAttribute;
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
>
> @Entity
> @XmlRootElement
> public class Library implements Serializable {
>     @Id
>     @Column(
>         name="LIBRARY_NAME",
>         nullable = false
>     )
>     @XmlAttribute (name = "name", required = true)
>     private String name;
>
>     @OneToMany(
>         cascade = CascadeType.ALL,
>         mappedBy = "library"
>     )
>     @XmlElement (name = "book")
>     private Set books = new HashSet();
>
>     public String getName() {
>         return name;
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public Book getBook(String name) {
>         for (Book b: books) {
>             if (b.getName().equals(name)) {
>                 return b;
>             }
>         }
>
>         return null;
>     }
>
>     public void putBook(Book book) {
>         book.setLibrary(this);
>         books.add(book);
>     }
>
>     public boolean equals(Object o) {
>         if (!(o instanceof Library)) {
>             return false;
>         }
>
>         Library other = (Library)o;
>
>         if (!getName().equals(other.getName())) {
>             return false;
>         }
>
>         return true;
>     }
>
>     public int hashCode() {
>         return getName().hashCode();
>     }
>
> }
> package com.mycompany.book;
>
> import java.io.Serializable;
> import javax.persistence.CascadeType;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.IdClass;
> import javax.persistence.ManyToOne;
> import javax.xml.bind.annotation.XmlAttribute;
>
> @IdClass(com.mycompany.book.PageId.class)
> @Entity
> public class Page implements Serializable {
>     @Id
>     @Column(
>         name="PAGE_NUMBER",
>         nullable = false
>     )
>     @XmlAttribute
>     private int number;
>
>     @Id
>     @Column(
>         nullable = false
>     )
>     @ManyToOne (
>       cascade = CascadeType.ALL
>     )
>     private Book book;
>
>     public int getNumber() {
>         return number;
>     }
>
>     public void setNumber(int number) {
>         this.number = number;
>     }
>
>     public Book getBook() {
>         return book;
>     }
>
>     public void setBook(Book book) {
>         this.book = book;
>     }
> }
> package com.mycompany.book;
>
> import java.io.Serializable;
> import javax.xml.bind.annotation.XmlTransient;
>
> @XmlTransient
> public class PageId implements Serializable {
>     private int number;
>     private BookId book;
>
>     public int getNumber() {
>         return number;
>     }
>
>     public void setNumber(int number) {
>         this.number = number;
>     }
>
>     public boolean equals(Object o) {
>         if (!(o instanceof PageId)) {
>             return false;
>         }
>
>         PageId other = (PageId)o;
>
>         if (!(getNumber() == other.getNumber())) {
>             return false;
>         }
>
>         if (!getBook().equals(other.getBook())) {
>             return false;
>         }
>
>         return true;
>     }
>
>     public int hashCode() {
>         return number * getBook().hashCode();
>     }
>
>     public BookId getBook() {
>         return book;
>     }
>
>     public void setBook(BookId book) {
>         this.book = book;
>     }
> }

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





 
---------------------------------
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.

Re: composite ID w/ another composite ID as a field

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Jeff,

The pattern you use for Book/Library is
> public class BookId implements Serializable {
>     private String name;
>     private String library;

The pattern you use for Page/Book is
> public class PageId implements Serializable {
>     private int number;
>     private BookId book;

Have you tried

> public class PageId implements Serializable {
>     private int number;
>     private String book;

Craig

On Apr 2, 2007, at 10:41 AM, jeff wrote:

> say i have Library, Book, and Page classes. a Library has many  
> Books, and a Book has many Pages. A Library's ID is it's name  
> (simple). A Book's ID is a composite of it's name and it's owning  
> Library's name (bidirectional relationship). A Page's ID is a  
> composite of it's number and it's owning Book's ID, a BookID.
>
> so, the PageId class starts like:
>
> public class PageId implements Serializable {
>     private int number;
>     private BookId book;
>
> the error i'm getting is at runtime ...
>
> <4|true|0.9.6-incubating>  
> org.apache.openjpa.persistence.ArgumentException: Field  
> "com.mycompany.book.Book.pages" declares  
> "com.mycompany.book.Page.book" as its mapped-by field, but this  
> field is not a direct relation.
>
> first, is what i'm trying to do even valid? i suspect it is not,  
> and the problem is that the fields of the ID class must be "simple"  
> types  (i believe the spec demands that). although, the error  
> message is a little confusing so i am not sure.
>
> it occurs to me that another way to achieve this would be to add  
> bookName and libraryName fields to the Page class, and add a  
> @PrePersist method that populates them by calling book.getName()  
> and book.getLibrary().getName(). but again this is messy because  
> that data is already in the table because of the bidirectional  
> relationship between the objects.
>
> as always, i'm open to "what are you an idiot?" responses if i am  
> just going about trying to define the Library, Book, Page  
> relationship in an obtuse manner.
>
> classes attached.
>
> The fish are biting.
> Get more visitors on your site using Yahoo! Search Marketing.
> package com.mycompany.book;
>
> import java.io.Serializable;
> import java.util.HashSet;
> import java.util.Set;
> import javax.persistence.CascadeType;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.IdClass;
> import javax.persistence.ManyToOne;
> import javax.persistence.OneToMany;
> import javax.xml.bind.annotation.XmlAttribute;
> import javax.xml.bind.annotation.XmlElement;
>
> @IdClass(com.mycompany.book.BookId.class)
> @Entity
> public class Book implements Serializable {
>     @Id
>     @Column(
>         name="BOOK_NAME",
>         nullable = false
>     )
>     @XmlAttribute (required = true)
>     private String name;
>
>     @OneToMany(
>         cascade = CascadeType.ALL,
>         mappedBy = "book"
>     )
>     @XmlElement (name = "page")
>     private Set<Page> pages = new HashSet<Page>();
>
>     @Id
>     @Column(
>         nullable = false
>     )
>     @ManyToOne (
>       cascade = CascadeType.ALL
>     )
>     private Library library;
>
>     public String getName() {
>         return name;
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public Page getPage(int n) {
>         for (Page p: pages) {
>             if (p.getNumber() == n) {
>                 return p;
>             }
>         }
>
>         return null;
>     }
>
>     public void putPage(Page p) {
>         p.setBook(this);
>         pages.add(p);
>     }
>
>     public boolean equals(Object o) {
>         if (!(o instanceof Book)) {
>             return false;
>         }
>
>         Book other = (Book)o;
>
>         if (!getName().equals(other.getName())) {
>             return false;
>         }
>
>         return true;
>     }
>
>     public int hashCode() {
>         return getName().hashCode();
>     }
>
>     public Library getLibrary() {
>         return library;
>     }
>
>     public void setLibrary(Library library) {
>         this.library = library;
>     }
>
> }
> package com.mycompany.book;
>
> import java.io.Serializable;
> import javax.xml.bind.annotation.XmlTransient;
>
> @XmlTransient
> public class BookId implements Serializable {
>     private String name;
>     private String library;
>
>
>     public boolean equals(Object o) {
>         if (!(o instanceof BookId)) {
>             return false;
>         }
>
>         BookId other = (BookId)o;
>
>         if (!(getName().equals(other.getName()))) {
>             return false;
>         }
>
>         if (!getLibrary().equals(other.getLibrary())) {
>             return false;
>         }
>
>         return true;
>     }
>
>     public int hashCode() {
>         return getName().hashCode() * getLibrary().hashCode();
>     }
>
>     public String getName() {
>         return name;
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public String getLibrary() {
>         return library;
>     }
>
>     public void setLibrary(String library) {
>         this.library = library;
>     }
> }
> package com.mycompany.book;
>
> import java.io.Serializable;
> import java.util.HashSet;
> import java.util.Set;
> import javax.persistence.CascadeType;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.OneToMany;
> import javax.xml.bind.annotation.XmlAttribute;
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
>
> @Entity
> @XmlRootElement
> public class Library implements Serializable {
>     @Id
>     @Column(
>         name="LIBRARY_NAME",
>         nullable = false
>     )
>     @XmlAttribute (name = "name", required = true)
>     private String name;
>
>     @OneToMany(
>         cascade = CascadeType.ALL,
>         mappedBy = "library"
>     )
>     @XmlElement (name = "book")
>     private Set<Book> books = new HashSet<Book>();
>
>     public String getName() {
>         return name;
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public Book getBook(String name) {
>         for (Book b: books) {
>             if (b.getName().equals(name)) {
>                 return b;
>             }
>         }
>
>         return null;
>     }
>
>     public void putBook(Book book) {
>         book.setLibrary(this);
>         books.add(book);
>     }
>
>     public boolean equals(Object o) {
>         if (!(o instanceof Library)) {
>             return false;
>         }
>
>         Library other = (Library)o;
>
>         if (!getName().equals(other.getName())) {
>             return false;
>         }
>
>         return true;
>     }
>
>     public int hashCode() {
>         return getName().hashCode();
>     }
>
> }
> package com.mycompany.book;
>
> import java.io.Serializable;
> import javax.persistence.CascadeType;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.IdClass;
> import javax.persistence.ManyToOne;
> import javax.xml.bind.annotation.XmlAttribute;
>
> @IdClass(com.mycompany.book.PageId.class)
> @Entity
> public class Page implements Serializable {
>     @Id
>     @Column(
>         name="PAGE_NUMBER",
>         nullable = false
>     )
>     @XmlAttribute
>     private int number;
>
>     @Id
>     @Column(
>         nullable = false
>     )
>     @ManyToOne (
>       cascade = CascadeType.ALL
>     )
>     private Book book;
>
>     public int getNumber() {
>         return number;
>     }
>
>     public void setNumber(int number) {
>         this.number = number;
>     }
>
>     public Book getBook() {
>         return book;
>     }
>
>     public void setBook(Book book) {
>         this.book = book;
>     }
> }
> package com.mycompany.book;
>
> import java.io.Serializable;
> import javax.xml.bind.annotation.XmlTransient;
>
> @XmlTransient
> public class PageId implements Serializable {
>     private int number;
>     private BookId book;
>
>     public int getNumber() {
>         return number;
>     }
>
>     public void setNumber(int number) {
>         this.number = number;
>     }
>
>     public boolean equals(Object o) {
>         if (!(o instanceof PageId)) {
>             return false;
>         }
>
>         PageId other = (PageId)o;
>
>         if (!(getNumber() == other.getNumber())) {
>             return false;
>         }
>
>         if (!getBook().equals(other.getBook())) {
>             return false;
>         }
>
>         return true;
>     }
>
>     public int hashCode() {
>         return number * getBook().hashCode();
>     }
>
>     public BookId getBook() {
>         return book;
>     }
>
>     public void setBook(BookId book) {
>         this.book = book;
>     }
> }

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