openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeff <jeffrey.blatt...@yahoo.com>
Subject RE: composite ID w/ another composite ID as a field
Date Mon, 02 Apr 2007 21:12:08 GMT
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 <ppoddar@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.
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message