persistence@glassfish.java.net

RE: Problem using ManyToMany relationship

From: Romanowski, Tim <tim.romanowski_at_lmco.com>
Date: Wed, 28 Mar 2007 19:45:21 -0400

Sadly, you already have them, in this chain of e-mails...the only mod that
we kept was setting the fetch. I can't post the entire classes, but here is
most of it. I did also add a supervisor field, as that also references the
Users entity and perhaps it has something to do with this:

@Entity
@Table(name = "TEAM")
public class Team implements Serializable {

    @SequenceGenerator(sequenceName="seq_teamid", name="teamid_gen",
initialValue=1, allocationSize=1)

    @Id @GeneratedValue(generator="teamid_gen")
    @Column(name = "TEAMID", nullable = false)
    private BigDecimal teamid;

@ManyToOne
    @JoinColumn(name = "supervisor", referencedColumnName = "USERNAME")
    private com.my.persistence.entity.Users supervisor;

@ManyToMany
    private java.util.Collection <com.my.persistence.entity.Users>
userCollection;

    @ManyToMany(fetch=FetchType.EAGER)
   @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;

    public void
setUserCollection(java.util.Collection<com.my.persistence.entity.Users>
userCollection) {
        this.userCollection = userCollection;
    }
} // End class Team

 

@Entity
@Table(name = "USERS")
public class Users implements Serializable {

    @Id
    @Column(name = "USERNAME", nullable = false)

    private String username;

    @ManyToMany(mappedBy="userCollection")
    private java.util.Collection <com.my.persistence.entity.Team>
teamCollection;

    public java.util.Collection <com.my.persistence.entity.Team>
getTeamCollection() {
        return this.teamCollection;
    }

    public void setTeamCollection(java.util.Collection
<com.my.persistence.entity.Team> teamCollection) {
        this.teamCollection = teamCollection;
    }
} // End class Users

 


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

Yes, you guessed it right - the access of the collection results in some
mismatch. Can you post your latest Team and User classes?

thanks,
-marina

Romanowski, Tim wrote:
> Ok, section 9.1.26, "FetchType fetch() default LAZY;". I didn't find that
> particularly clear, but I do see that Basic is only applicable to a
handful
> of types. Chapter 9 of the spec is not something I had looked at before.
>
> @ManyToMany(fetch=FetchType.EAGER)
> @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;
>
> However, now I'm back to square one. I'm getting this name mismatch
error.
> I thought, "must be a mismatch with the database join table." But I look,
> and my table is as expected:
>
> Table: team_users
> Columns: teamid, username
>
>
> ANY access to the Team entity is causing the exception below. But I do
have
> some new info: a single call to an instance of Users'
"getTeamCollection()"
> generates the following exception:
>
> 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
>
>
>
>
> However, if I instead access the Team entities "getUserCollection()," I
get
> a similar exception, but it says "Query:
> ReadAllQuery(com.my.persistence.entity.Users)", and "The parameter name
> [teamid] in the query's ..."
>