persistence@glassfish.java.net

Re: Problem using ManyToMany relationship

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 28 Mar 2007 17:49:56 -0700

Oh, yes, TopLink doesn't do case insensitive comparison of the values provided,
so they will be treated as different ones and apparently mess up the metadata.

Good luck with your next problem ;).

regards,
-marina

Romanowski, Tim wrote:
> Aha...I changed the capitalization of the name mapping for the @Column
> annotation of the primary keys of each entity, and it appears to have
> resolved the ongoing issue. I'm getting another exception related to a
> missing descriptor for the String type when I try to save an ArrayList...
> That is another issue, so I'm going to presume this one resolved until I can
> determine that that is truly separate. I'll post back with a definitive
> answer once I find out.
>
> Thanks for your help!
>
> Tim
>
> -----Original Message-----
> From: Romanowski, Tim
> Sent: Wednesday, March 28, 2007 8:08 PM
> To: persistence_at_glassfish.dev.java.net
> Subject: RE: Problem using ManyToMany relationship
>
> Sorry, the first one listed was a copy and paste error while formatting the
> e-mail. The getter is:
>
> public java.util.Collection<com.lmco.gems.persistence.entity.Users>
> getUserCollection() {
> return userCollection;
> }
>
> I'm really confused as to what is causing such a problem for such a mundane
> setup. Any other thoughts?
>
> Tim
>
> -----Original Message-----
> From: Marina.Vatkina_at_Sun.COM [mailto:Marina.Vatkina_at_Sun.COM]
> Sent: Wednesday, March 28, 2007 7:50 PM
> To: persistence_at_glassfish.dev.java.net
> Subject: Re: Problem using ManyToMany relationship
>
> Tim,
>
> Do you really have 2 fields called 'userCollection'? You also seem to miss a
>
> getter for it.
>
> thanks,
> -marina
>
> Romanowski, Tim wrote:
>
>>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 ..."
>>>