persistence@glassfish.java.net

RE: Problem using ManyToMany relationship

From: Romanowski, Tim <tim.romanowski_at_lmco.com>
Date: Wed, 28 Mar 2007 17:23:15 -0400

Now we're getting somewhere...you see, I never wrote "ReadAllQuery." In
fact, I can't find it anywhere in my project using a fulltext search. I
thought it was something Glassfish provided and used internally.

That being the case, I set the logging levels for the EJB Container and
Persistence to FINEST via the Glassfish Admin Console and reran my app. I
didn't get any more useful information. Where is ReadAllQuery coming from,
if it's not in my entity, nor in any of my other code (at least that
NetBeans search can find)? What else should I try to find this?

Here's what I have from FINEST logging:

Execute query ReadObjectQuery(com.my.persistence.entity.Users)
reconnecting to external connection pool
SELECT USERNAME, FIRSTNAME, PASSWORD, LASTNAME, ORGID FROM USERS WHERE
(USERNAME = ?)
        bind => [tromanow]
Execute query ReadObjectQuery(com.my.persistence.entity.Org)
reconnecting to external connection pool
SELECT ORGID, NAME, DESCRIPTION FROM ORG WHERE (ORGID = ?)
        bind => [10]
Register the existing object
com.my.persistence.entity.Users[username=tromanow]
Register the existing object com.my.persistence.entity.Org[orgid=10]
Execute query ReadAllQuery(com.my.persistence.entity.Team)
Local Exception Stack:
Exception [TOPLINK-6094] (Oracle TopLink Essentials - 2.0 (Build b40-rc
(03/20/2007))): oracle.toplink.essentials.exceptions.QueryException
Exception Description: The parameter name [username] in the query's
selection criteria does not match any parameter name defined in the query.
Query: ReadAllQuery(com.my.persistence.entity.Team)
        at
oracle.toplink.essentials.exceptions.QueryException.parameterNameMismatch(Qu
eryException.java:966)
        at
oracle.toplink.essentials.internal.expressions.ParameterExpression.getValue(
ParameterExpression.java:215)
        at
oracle.toplink.essentials.internal.databaseaccess.DatabaseCall.translate(Dat
abaseCall.java:821)
        at
oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechani
sm.executeCall(DatasourceCallQueryMechanism.java:212)
        at
oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechani
sm.executeCall(DatasourceCallQueryMechanism.java:199)
        at
oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechani
sm.executeSelectCall(DatasourceCallQueryMechanism.java:270)
        at
oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechani
sm.selectAllRows(DatasourceCallQueryMechanism.java:600)
        at
oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.s
electAllRowsFromTable(ExpressionQueryMechanism.java:2240)
        at
oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.s
electAllRows(ExpressionQueryMechanism.java:2218)
        at
oracle.toplink.essentials.queryframework.ReadAllQuery.executeObjectLevelRead
Query(ReadAllQuery.java:302)
        at
oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeDatabas
eQuery(ObjectLevelReadQuery.java:709)
        at
oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery
.java:609)
        at
oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.execute(Object
LevelReadQuery.java:677)
        at
oracle.toplink.essentials.internal.sessions.AbstractSession.internalExecuteQ
uery(AbstractSession.java:1815)


-----Original Message-----
From: Marina.Vatkina_at_Sun.COM [mailto:Marina.Vatkina_at_Sun.COM]
Sent: Wednesday, March 28, 2007 4:34 PM
To: persistence_at_glassfish.dev.java.net
Subject: Re: Problem using ManyToMany relationship

Hi Tim,

Romanowski, Tim wrote:
> Hi Marina,
> I was only using AtrributeOverride based on another example I found while
> googling a couple months ago; I forget what the reasoning was, but I
looked
> at the spec, agreed with the example writers explanation, and moreso,
found
> that it allowed me to compile & deploy my app. In hindsight, I have to
> assume that I changed more than one thing at a time and attributed the
"fix"
> to the wrong code. As I mentioned in my last e-mail, I removed
> @AttributeOverride a couple hours ago, and it did not appear to affect my
> app in anyway, so all I can plead is insanity =)
>
> So, where does that leave me? With a couple questions:
>
> 1) In the newer code I posted below, is there an obvious reason why
> NetBeans would be reporting:
>
> "Inconsistent access type in entity class because a field in this class
or
> its super class chain is already annotated as @Id or @EmbeddedId."

@Id or @EmbeddedId are the annotations that define access type (because
either
one is required in entity that uses annotations). Which means that if there
are
annotations that are also placed on a getter as in your example below, it's
an
error.

>
> I do not see how this "inconsistent access type" is even relevant...I am
> annotating the getter of a field, and that field is NOT the id of the
entity
> (in this case, entity Team).

While it's probably doable to have mixed annotations, it's not supported by
the
spec, so there is no requirement for the persistence providers to support it
either.

>
>
> 2) How do I annotate my userCollection field in the Team entity, instead
of
> the getUserCollection method in that same entity? If do so with this:
> @ManyToMany
> @JoinTable(name = "team_users",
> joinColumns = {_at_JoinColumn(name = "teamid", referencedColumnName =
> "teamid")},
> inverseJoinColumns = {_at_JoinColumn(name = "username",
> referencedColumnName = "username")})
> private java.util.Collection <com.my.persistence.entity.Users>
> userCollection;

The annotation on the field or property should be the same.

The exception below comes from a query - can you post it here?

thanks,
-marina

>
> I get this:
> Local Exception Stack:
> Exception [TOPLINK-6094] (Oracle TopLink Essentials - 2.0 (Build b40-rc
> (03/20/2007))): oracle.toplink.essentials.exceptions.QueryException
> Exception Description: The parameter name [username] in the query's
> selection criteria does not match any parameter name defined in the query.
> Query: ReadAllQuery(com.my.persistence.entity.Team)
> at
>
oracle.toplink.essentials.exceptions.QueryException.parameterNameMismatch(Qu
> eryException.java:966)
> at
>
oracle.toplink.essentials.internal.expressions.ParameterExpression.getValue(
> ParameterExpression.java:215)
> at
>
oracle.toplink.essentials.internal.databaseaccess.DatabaseCall.translate(Dat
> abaseCall.java:821)
> at
>
oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechani
> sm.executeCall(DatasourceCallQueryMechanism.java:212)
>
>
>
> -----Original Message-----
> From: Marina.Vatkina_at_Sun.COM [mailto:Marina.Vatkina_at_Sun.COM]
> Sent: Wednesday, March 28, 2007 4:02 PM
> To: persistence_at_glassfish.dev.java.net
> Subject: Re: Problem using ManyToMany relationship
>
> Tim,
>
> All annotations should be placed in a similar way - either on the fields
or
> on
> the properties (i.e. getters). The current spec doesn't allow to mix them
> not
> only in the same class, but even in an inheritance hierarchy.
>
> Why do you need to use @AttributeOverride? Here is what the spec says:
>
> 9.1.10 AttributeOverride Annotation
>
> The AttributeOverride annotation is used to override the mapping of a
Basic
> (whether explicit or default) property or field or Id property or field.
The
>
> AttributeOverride annotation may be applied to an entity that extends a
> mapped
> superclass or to an embedded field or property to override a basic mapping

> defined by the mapped superclass or embeddable class.
>
> Regards,
> -marina
>