You can consider the table as a secondary table, in which there is at most one row in the join table for each row in the main table. You would use the @SecondaryTable annotation for this.
You can also consider the table to be a join table to map the relationship(s). You would use the @JoinTable annotation for this.
We should take a look and make sure that both mapping styles work for OpenJPA.
Craig On Nov 5, 2007, at 6:11 PM, Patrick Linskey wrote:
Hmm. Looking at 2.1.8.3.2, it seems that unidirectional ManyToOnes are legal. Maybe there's a bug in OpenJPA when putting a unidirectional ManyToOne into a secondary table or something, or maybe it's just a bug in all unidirectional ManyToOne cases. -Patrick On Nov 5, 2007 6:02 PM, Geir Magnusson Jr. <[EMAIL PROTECTED]> wrote:On Nov 5, 2007, at 8:22 PM, Patrick Linskey wrote:I believe it's unidirectional ManyToOne (if that's legal). EachInputFile is associated with one Show and one Show only, but multipleInputFiles can be associated to the same Show.I believe that what you're describing is a unidirectional one-to-one with a join table. I think that you can model this with a secondary table.I tried that after sending the mail below, and it worked.@ManyToOne sounds like it's describing an ER concept, but I believe that in reality, it's reserved for the backpointer of a @OneToMany.Why?-Patrick On 11/5/07, Geir Magnusson Jr. <[EMAIL PROTECTED]> wrote:To review, I have three tables : Show, InputFile and a join table, Show2InputFile. Show happens to be a subclass of InventoryItem using JOINED inheritance strategy. Not sure if that matters. (I've seen someweird behavior w/ Hibernate w/ JOINED, so I'm suspicious of it for norational reason) Show has a PK "id", as does InputFile. Show2InputFile looks like : +-------------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+-------+ | showId | int(11) unsigned | NO | PRI | | | | inputFileId | int(11) unsigned | NO | PRI | | | +-------------+------------------+------+-----+---------+-------+ I believe it's unidirectional ManyToOne (if that's legal). EachInputFile is associated with one Show and one Show only, but multipleInputFiles can be associated to the same Show. Currently I have in InputFile : @ManyToOne @JoinTable(name="Show2InputFile", joinColumns = @JoinColumn(name="inputFileId"), inverseJoinColumns = @JoinColumn(name="showId")) public Show getShow() { return show; }and while Hibernate thinks that's just peachy, OpenJPA 1.0.0 gags onit with Caused by: <openjpa-1.1.0-SNAPSHOT-r420667:588533 fatal user error> org.apache.openjpa.persistence.ArgumentException: You have supplied columns for "com.joost.model.logistics.InputFile.show<element:class java.lang.Object>", but this mapping cannot have columns in this context.Now, while I don't want to add anything to the Show class, since thisreally is unidirectional, I did add : @OneToMany @JoinTable(name="Show2InputFile", inverseJoinColumns = @JoinColumn(name="inputFileId"), joinColumns = @JoinColumn(name="showId")) public Set<InputFile> getInputFiles(){ return null; } public void setInputFiles(Set<InputFile> list) { //noop } just to see if that would make OpenJPA happy, but as far as I can see, it doesn't. I believe I get the same error message. I really want to switch to OpenJPA, but this is stopping me. Does anyone have any idea what I'm doing wrong? geir On Nov 5, 2007, at 3:05 PM, Patrick Linskey wrote:Where are the foreign keys?Bear in mind that @OneToOne, @OneToMany, @ManyToMany, and @ManyToOne are JPA annotations, not ER annotations. The concepts differ a bit.-PatrickOn Nov 5, 2007 11:33 AM, Geir Magnusson Jr. <[EMAIL PROTECTED]> wrote:On Nov 5, 2007, at 2:07 PM, Patrick Linskey wrote:What happens if you just use a @OneToOne instead of the @ManyToOne?The problem is that it's not OneToOneCan you describe this in more detail? (I.e., in terms of what yourschema looks like.)Well, there's a Show table, w/ a pk, and the Show class really has no interest in the InputFile class. There's an inputfile table, w/ a pk. The InputFile class does have a ManyToOne with Show : In real world problem, each Show we have on the platform is a singleton ("I dream of Genie Epsode 11"), but a content owner maygive us updated source material - say they have a new transcoding.We want to add a new InputFile into the database, point it at the Show, but the Show itself doesn't care about it's source. Does that help? eir-Patrick On Nov 5, 2007 10:40 AM, Geir Magnusson Jr. <[EMAIL PROTECTED]> wrote:On Nov 5, 2007, at 12:44 PM, Patrick Linskey wrote:I'm a newbie, so I don't quite grok the question. Show itselfdoesn't have any references to InputFile.Aha! IIRC, @ManyToOne is only meaningful when used as the back side of a @OneToMany.We don't have that. There are reasons, and its intentional.What happens if you just use a @OneToOne instead of the @ManyToOne?The problem is that it's not OneToOne-Patrick On Nov 5, 2007 9:16 AM, Geir Magnusson Jr. <[EMAIL PROTECTED]> wrote:On Nov 5, 2007, at 11:48 AM, Patrick Linskey wrote:Hi, What does the other side of the relation look like?I'm a newbie, so I don't quite grok the question. Show itselfdoesn't have any references to InputFile.Also, what does the Show class look like?in what way? Show is a subclass in a JOINED inheritance strategy, if that makes any difference. geir-Patrick On Nov 5, 2007 8:08 AM, Geir Magnusson Jr. <[EMAIL PROTECTED]> wrote:I'm a newbie, so forgive me if I'm not asking the question the right way. I have a join table in my DB : +-------------+------------------+------+-----+--------- +-------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+--------- +-------+ | showId | int(11) unsigned | NO | PRI | | | | inputFileId | int(11) unsigned | NO | PRI | | | +-------------+------------------+------+-----+--------- +-------+ where showId and inputFileID are PKs in the show table and inputfile table. In my code for the InputFile class : @ManyToOne @JoinTable(name="Show2InputFile", joinColumns = @JoinColumn(name="inputFileId"),inverseJoinColumns = @JoinColumn (name="showId"))public Show getShow() { return show; } When JPA is instrumenting my classes, it complains :Caused by: <openjpa-1.1.0-SNAPSHOT-r420667:588533 fatal usererror> org.apache.openjpa.persistence.ArgumentException: You have supplied columns for "com.joost.model.logistics.InputFile.show<element:class java.lang.Object>", but this mapping cannot have columns in this context. I don't quite understand the error. I use this same thing elsewhere (I think) w/o a problem. Can someone give me a hint? geir-- Patrick Linskey 202 669 5907-- Patrick Linskey 202 669 5907-- Patrick Linskey 202 669 5907-- Patrick Linskey 202 669 5907-- Patrick Linskey 202 669 5907-- Patrick Linskey 202 669 5907
Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:[EMAIL PROTECTED] P.S. A good JDO? O, Gasp!
smime.p7s
Description: S/MIME cryptographic signature
