You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Nick Johnson <ap...@spatula.net> on 2007/11/06 03:29:38 UTC
Many:Many relation ignored
It's probably just something I'm not seeing...
I have two entities in this relationship, Article and Account. Accounts
may have votes recorded for articles, and I track this by a many:many
relationship between Articles and the Accounts that voted. (One account
may vote on many Articles, and Articles may have votes from many
accounts.)
The symptom is that the Set annotated with @ManyToMany is always null and
additions to the Set are not persisted.
I have a join table called article_votes which looks like this:
article_object_id | integer | not null
account_object_id | integer | not null
In Article.java, I've annotated articleVotes like this:
@ManyToMany
@JoinTable(name="article_votes", inverseJoinColumns =
{@JoinColumn(name = "account_object_id", referencedColumnName =
"object_id")})
private Set<Account> articleVotes;
And in Account.java, I've annotated it like this:
@ManyToMany
@JoinTable(name = "article_votes", joinColumns = {@JoinColumn(name =
"account_object_id")}, inverseJoinColumns = {@JoinColumn(name =
"article_object_id")})
private Set<Article> articleVotes;
The problem is that when I read an Article from the database, the
articleVotes set is always null. If I create a HashSet and populated
it and persist the change, OpenJPA performs no insert into the join table.
I can't imagine that Many:Many doesn't work, so it's probably some detail
I'm overlooking.
Any thoughts or suggestions?
Nick
--
"Courage isn't just a matter of not being frightened, you know. It's being
afraid and doing what you have to do anyway."
Doctor Who - Planet of the Daleks
This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
http://healerNick.com/ http://morons.org/ http://spatula.net/
Re: Many:Many relation ignored
Posted by Nick Johnson <ap...@spatula.net>.
On Tue, 6 Nov 2007, Patrick Linskey wrote:
> > If I use the javaagent as you described, the test passes. If I omit the
> > javaagent entirely, the test fails (because the m:m field is null).
>
> Cool, thanks for testing that out. One more question: is this
> happening with a new instance (i.e., one that you call persist() on),
> or on an instance that you've looked up from the DB?
This is happening on an instance that I've looked up from the DB. I would
expect the field to be null on a new object that had not yet been
persisted, unless the collection were already initialized in the
declaration.
One thing that's also interesting is that if I define the field so that
it's initialized in the declaration (e.g. Set<Bar> foo = new
HashSet<Bar>()), it still ends up being null when retrieved from the
database... so it would appear that it is being explicitly set to a null
value at some point. (Though I don't discount the possibility that
something else could be happening as well.)
Nick
--
"Courage isn't just a matter of not being frightened, you know. It's being
afraid and doing what you have to do anyway."
Doctor Who - Planet of the Daleks
This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
http://healerNick.com/ http://morons.org/ http://spatula.net/
Re: Many:Many relation ignored
Posted by Patrick Linskey <pl...@gmail.com>.
> If I use the javaagent as you described, the test passes. If I omit the
> javaagent entirely, the test fails (because the m:m field is null).
Cool, thanks for testing that out. One more question: is this
happening with a new instance (i.e., one that you call persist() on),
or on an instance that you've looked up from the DB?
> I presume I'm using field enhancement though I haven't gone out of my way
> to specify that... the class uses field access (not property access)
> anyway.
Yeah, that's what I meant. Thanks.
-Patrick
On Nov 6, 2007 9:57 AM, Nick Johnson <ap...@spatula.net> wrote:
> This is with Java 5.
>
> If I use the javaagent as you described, the test passes. If I omit the
> javaagent entirely, the test fails (because the m:m field is null).
>
> I presume I'm using field enhancement though I haven't gone out of my way
> to specify that... the class uses field access (not property access)
> anyway.
>
> Nick
>
>
> On Tue, 6 Nov 2007, Patrick Linskey wrote:
>
> > Hi,
> >
> > Are you using Java 5 or 6? If 5, what happens if you run the javaagent
> > with the ClassLoadEnhancement flag set to false [1]? Are you using
> > field or property enhancement?
> >
> > [1] java -javaagent:foo.jar=ClassLoadEnhancement=false ...
> >
> > -Patrick
> >
> > On Nov 5, 2007 6:51 PM, Nick Johnson <ap...@spatula.net> wrote:
> > > Just a tidbit more information here... I just discovered that it works OK
> > > if I specify a javaagent when running my unit test, so it looks like the
> > > trouble has something to do with enhancing versus not enhancing.
> > >
> > > On Mon, 5 Nov 2007, Nick Johnson wrote:
> > >
> > > > It's probably just something I'm not seeing...
> > > [snip]
> > >
> > >
> > > --
> > > "Courage isn't just a matter of not being frightened, you know. It's being
> > > afraid and doing what you have to do anyway."
> > > Doctor Who - Planet of the Daleks
> > > This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
> > > http://healerNick.com/ http://morons.org/ http://spatula.net/
> > >
> >
> >
> >
> >
>
> --
> "Courage isn't just a matter of not being frightened, you know. It's being
> afraid and doing what you have to do anyway."
> Doctor Who - Planet of the Daleks
> This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
> http://healerNick.com/ http://morons.org/ http://spatula.net/
>
--
Patrick Linskey
202 669 5907
Re: Many:Many relation ignored
Posted by Nick Johnson <ap...@spatula.net>.
This is with Java 5.
If I use the javaagent as you described, the test passes. If I omit the
javaagent entirely, the test fails (because the m:m field is null).
I presume I'm using field enhancement though I haven't gone out of my way
to specify that... the class uses field access (not property access)
anyway.
Nick
On Tue, 6 Nov 2007, Patrick Linskey wrote:
> Hi,
>
> Are you using Java 5 or 6? If 5, what happens if you run the javaagent
> with the ClassLoadEnhancement flag set to false [1]? Are you using
> field or property enhancement?
>
> [1] java -javaagent:foo.jar=ClassLoadEnhancement=false ...
>
> -Patrick
>
> On Nov 5, 2007 6:51 PM, Nick Johnson <ap...@spatula.net> wrote:
> > Just a tidbit more information here... I just discovered that it works OK
> > if I specify a javaagent when running my unit test, so it looks like the
> > trouble has something to do with enhancing versus not enhancing.
> >
> > On Mon, 5 Nov 2007, Nick Johnson wrote:
> >
> > > It's probably just something I'm not seeing...
> > [snip]
> >
> >
> > --
> > "Courage isn't just a matter of not being frightened, you know. It's being
> > afraid and doing what you have to do anyway."
> > Doctor Who - Planet of the Daleks
> > This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
> > http://healerNick.com/ http://morons.org/ http://spatula.net/
> >
>
>
>
>
--
"Courage isn't just a matter of not being frightened, you know. It's being
afraid and doing what you have to do anyway."
Doctor Who - Planet of the Daleks
This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
http://healerNick.com/ http://morons.org/ http://spatula.net/
Re: Many:Many relation ignored
Posted by Patrick Linskey <pl...@gmail.com>.
Hi,
Are you using Java 5 or 6? If 5, what happens if you run the javaagent
with the ClassLoadEnhancement flag set to false [1]? Are you using
field or property enhancement?
[1] java -javaagent:foo.jar=ClassLoadEnhancement=false ...
-Patrick
On Nov 5, 2007 6:51 PM, Nick Johnson <ap...@spatula.net> wrote:
> Just a tidbit more information here... I just discovered that it works OK
> if I specify a javaagent when running my unit test, so it looks like the
> trouble has something to do with enhancing versus not enhancing.
>
> On Mon, 5 Nov 2007, Nick Johnson wrote:
>
> > It's probably just something I'm not seeing...
> [snip]
>
>
> --
> "Courage isn't just a matter of not being frightened, you know. It's being
> afraid and doing what you have to do anyway."
> Doctor Who - Planet of the Daleks
> This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
> http://healerNick.com/ http://morons.org/ http://spatula.net/
>
--
Patrick Linskey
202 669 5907
Re: Many:Many relation ignored
Posted by Nick Johnson <ap...@spatula.net>.
Just a tidbit more information here... I just discovered that it works OK
if I specify a javaagent when running my unit test, so it looks like the
trouble has something to do with enhancing versus not enhancing.
On Mon, 5 Nov 2007, Nick Johnson wrote:
> It's probably just something I'm not seeing...
[snip]
--
"Courage isn't just a matter of not being frightened, you know. It's being
afraid and doing what you have to do anyway."
Doctor Who - Planet of the Daleks
This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
http://healerNick.com/ http://morons.org/ http://spatula.net/