You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Fernando Padilla <fe...@alum.mit.edu> on 2008/10/16 07:23:54 UTC
having issues with first query.
Hello. I'm in the process of converting a project from JDO (kodo
3.3.4), into OpenJPA. And now I need some help, because it's failing on
the second query that it runs. :)
Below you'll see the first query, loading up a "Fan" object via a field
"fbId". The second query tries to load a "TeamFan" object via 2 fields,
"fan" and "teamId". "fan" is of type "Fan". "teamId" is of type
"TeamId", using @Externalizer.
For the second query it complains:
"The specified parameter of type "class
com.protrade.fandom.data.entities.Fan" is not a valid query parameter."
Even though Fan is a valid Entity, that I just got from OpenJPA a
fraction of a second before I used it in a query.
Please help! :)
Any ideas of what could be going on?
#1
The first query succeeds:
2008-10-15 22:05:56,381 [btpool0-1] DEBUG openjpa.Query - Executing
query: [select this from com.protrade.fandom.data.entities.Fan this
where this.fbId = :p0] with parameters: {p0=578696943}
2008-10-15 22:05:56,447 [btpool0-1] DEBUG openjpa.jdbc.SQL - <t
10097681, conn 17988685> executing prepstmnt 29597895 SELECT t0.JDOID,
t0.CREATETIME, t0.beboId, t0.fbId, t0.hi5Id, t0.mosId FROM FAN t0 WHERE
(t0.fbId = ?) [params=(long) 578696943]
2008-10-15 22:05:56,448 [btpool0-1] DEBUG openjpa.jdbc.SQL - <t
10097681, conn 17988685> [0 ms] spent
2008-10-15 22:05:56,459 [btpool0-1] DEBUG openjpa.DataCache - Cache miss
while looking up key "com.protrade.fandom.data.entities.Fan-2".
2008-10-15 22:05:56,459 [btpool0-1] DEBUG openjpa.DataCache - Cache miss
while looking up key "com.protrade.fandom.data.entities.Fan-2".
2008-10-15 22:05:56,463 [btpool0-1] DEBUG openjpa.DataCache - Put key
"com.protrade.fandom.data.entities.Fan-2" into cache.
2008-10-15 22:05:56,463 [btpool0-1] DEBUG openjpa.DataCache - Cache hit
while looking up key "com.protrade.fandom.data.entities.Fan-2".
2008-10-15 22:05:56,463 [btpool0-1] DEBUG openjpa.jdbc.JDBC - <t
10097681, conn 17988685> [0 ms] close
#2
but the second query fails:
2008-10-15 22:05:56,530 [btpool0-1] DEBUG openjpa.Query - Executing
query: [select this from com.protrade.fandom.data.entities.TeamFan this
where this.fan = :p0 AND this.teamId = :p1] with parameters:
{p1=<<FbTeamId:FbTeam:2086>>,
p0=com.protrade.fandom.data.entities.Fan@14d6015[
beboId=<null>
fbId=578696943
hi5Id=<null>
mosId=<null>
createTime=1191032532627
id=2
jdoId=<null>
jdoversion=0
]}
<openjpa-1.2.0-r422266:683325 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: The specified
parameter of type "class com.protrade.fandom.data.entities.Fan" is not a
valid query parameter.
at
org.apache.openjpa.jdbc.sql.DBDictionary.setUnknown(DBDictionary.java:1348)
at org.apache.openjpa.jdbc.sql.SQLBuffer.setParameters(SQLBuffer.java:630)
at
org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:529)
at
org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:485)
at
org.apache.openjpa.jdbc.sql.SelectImpl.prepareStatement(SelectImpl.java:463)
at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:379)
at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:339)
at
org.apache.openjpa.jdbc.sql.LogicalUnion$UnionSelect.execute(LogicalUnion.java:420)
at org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:230)
at org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:220)
at org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:206)
at
org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.open(SelectResultObjectProvider.java:94)
at org.apache.openjpa.kernel.QueryImpl.singleResult(QueryImpl.java:1284)
at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1221)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:990)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:848)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:779)
at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:525)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:253)
at
org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:316)
at com.protrade.common.persistence.JPAUtil.execute(JPAUtil.java:142)
Re: having issues with first query.
Posted by Fernando Padilla <fe...@alum.mit.edu>.
I don't know if this is a clue but this is what I see in debug, when
it's dealing with the TeamFan metadata. Just not sure if
"HandlerFieldStrategy" is correct or not..
2008-10-16 10:56:08,472 [btpool0-1] DEBUG openjpa.MetaData - Resolving
field "com.protrade.fandom.data.entities.TeamFan@27999450.fan".
2008-10-16 10:56:08,472 [btpool0-1] DEBUG openjpa.MetaData - "fan" has
mapping strategy "org.apache.openjpa.jdbc.meta.strats.HandlerFieldStrategy".
Fernando Padilla wrote:
> thank you for replying!
>
> Fan and TeamFan are entities of course. They extend a MappedSuperclass.
> Here are the four classes involved in this query. Fan and TeamFan
> extend HBaseIdCreateTime, which extends HBaseId.
>
> And just to recap from last email:
>
> I load a "Fan" object via the "fbId" field, and that works just fine.
> Then I try to load a "TeamFan" object via that "Fan" object just loaded,
> and a "teamId". But it complains that the Fan is not a valid type:
>
> <openjpa-1.2.0-r422266:683325 nonfatal user error>
> org.apache.openjpa.persistence.ArgumentException: The specified
> parameter of type "class com.protrade.fandom.data.entities.Fan" is not a
> valid query parameter.
>
>
>
>
>
>
>
> @Entity
> @Table(name = "TEAMFAN")
> public class TeamFan extends HBaseIdCreateTime {
> @Column(name = "FAN_JDOID")
> private Fan fan;
>
> @Column(name = "TEAMID")
> @Externalizer("getIdLong")
> private FbTeamId teamId;
> .....
>
>
> @Entity
> @Table(name = "FAN")
> public class Fan extends HBaseIdCreateTime implements UnifiedSocialUser{
> @Column(name = "BEBOID")
> private Long beboId;
> @Column(name = "FBID")
> private Long fbId;
> @Column(name = "HI5ID")
> private String hi5Id;
> @Column(name = "MOSID")
> private String mosId;
> .....
>
>
> @MappedSuperclass
> public class HBaseIdCreateTime extends HBaseId implements
> BaseIdCreateTime {
> @Basic
> @Column(name = "CREATETIME")
> private long createTime;
> .....
>
>
> @MappedSuperclass
> public class HBaseId extends BaseObject implements BaseId, Serializable{
> @Id
> @Column(name = "JDOID")
> @GeneratedValue
> private Long id;
>
> @Version
> @Column(name = "JDOVERSION")
> private long jdoversion;
> .....
>
>
>
> Jeremy Bauer wrote:
>> Hi Fernando,
>>
>> Is TeamFan also defined as an entity and is there an inheritance
>> strategy defined for the Fan - TeamFan hierarchy? If not, you'll need
>> to make sure you have a valid JPA inheritance hierarchy & strategy.
>> If this is the case, could you post your entity classes or even
>> better, a failing test case?
>>
>> -Jeremy
Re: having issues with first query.
Posted by Jeremy Bauer <te...@gmail.com>.
Hi Fernando,
I'm glad to see you got the code working. I was a bit off on my first
comments/assumptions. I assumed that TeamFan was a subclass of Fan.
Posting your entities and taking a closer look at your statement text
cleared that up. I was just about to suggest that you need to specify
1) a relationship (OneToOne or ManyToOne) with FAN_JDOID as the join
column or 2) tag Fan as embeddable; when I noticed your reply. It
sounds like the Kodo behavior maps to option 1).
I can't think of any shortcuts to automatically trigger the ManyToOne
relationship.
-Jeremy
Re: having issues with first query.
Posted by Fernando Padilla <fe...@alum.mit.edu>.
OK. I think i figured it out. I was assuming that OpenJPA would be
smart enough to figure out relationships to other entities (as kodo used
to do). But it looks like to fix this I have to explicitly add:
@ManyToOne
@JoinColumn(name = "FAN_JDOID")
private Fan fan;
Very annoying having to go through my whole data model and fill those
in, but at least better than the alternative of it not working at all! :)
So anyone have any shortcuts, so that OpenJPA would just make a
ManyToOne assumption? possibly?
Fernando Padilla wrote:
> thank you for replying!
>
> Fan and TeamFan are entities of course. They extend a MappedSuperclass.
> Here are the four classes involved in this query. Fan and TeamFan
> extend HBaseIdCreateTime, which extends HBaseId.
>
> And just to recap from last email:
>
> I load a "Fan" object via the "fbId" field, and that works just fine.
> Then I try to load a "TeamFan" object via that "Fan" object just loaded,
> and a "teamId". But it complains that the Fan is not a valid type:
>
> <openjpa-1.2.0-r422266:683325 nonfatal user error>
> org.apache.openjpa.persistence.ArgumentException: The specified
> parameter of type "class com.protrade.fandom.data.entities.Fan" is not a
> valid query parameter.
>
>
>
>
>
>
>
> @Entity
> @Table(name = "TEAMFAN")
> public class TeamFan extends HBaseIdCreateTime {
> @Column(name = "FAN_JDOID")
> private Fan fan;
>
> @Column(name = "TEAMID")
> @Externalizer("getIdLong")
> private FbTeamId teamId;
> .....
>
>
> @Entity
> @Table(name = "FAN")
> public class Fan extends HBaseIdCreateTime implements UnifiedSocialUser{
> @Column(name = "BEBOID")
> private Long beboId;
> @Column(name = "FBID")
> private Long fbId;
> @Column(name = "HI5ID")
> private String hi5Id;
> @Column(name = "MOSID")
> private String mosId;
> .....
>
>
> @MappedSuperclass
> public class HBaseIdCreateTime extends HBaseId implements
> BaseIdCreateTime {
> @Basic
> @Column(name = "CREATETIME")
> private long createTime;
> .....
>
>
> @MappedSuperclass
> public class HBaseId extends BaseObject implements BaseId, Serializable{
> @Id
> @Column(name = "JDOID")
> @GeneratedValue
> private Long id;
>
> @Version
> @Column(name = "JDOVERSION")
> private long jdoversion;
> .....
>
>
>
> Jeremy Bauer wrote:
>> Hi Fernando,
>>
>> Is TeamFan also defined as an entity and is there an inheritance
>> strategy defined for the Fan - TeamFan hierarchy? If not, you'll need
>> to make sure you have a valid JPA inheritance hierarchy & strategy.
>> If this is the case, could you post your entity classes or even
>> better, a failing test case?
>>
>> -Jeremy
Re: having issues with first query.
Posted by Fernando Padilla <fe...@alum.mit.edu>.
thank you for replying!
Fan and TeamFan are entities of course. They extend a MappedSuperclass.
Here are the four classes involved in this query. Fan and TeamFan
extend HBaseIdCreateTime, which extends HBaseId.
And just to recap from last email:
I load a "Fan" object via the "fbId" field, and that works just fine.
Then I try to load a "TeamFan" object via that "Fan" object just loaded,
and a "teamId". But it complains that the Fan is not a valid type:
<openjpa-1.2.0-r422266:683325 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: The specified
parameter of type "class com.protrade.fandom.data.entities.Fan" is not a
valid query parameter.
@Entity
@Table(name = "TEAMFAN")
public class TeamFan extends HBaseIdCreateTime {
@Column(name = "FAN_JDOID")
private Fan fan;
@Column(name = "TEAMID")
@Externalizer("getIdLong")
private FbTeamId teamId;
.....
@Entity
@Table(name = "FAN")
public class Fan extends HBaseIdCreateTime implements UnifiedSocialUser{
@Column(name = "BEBOID")
private Long beboId;
@Column(name = "FBID")
private Long fbId;
@Column(name = "HI5ID")
private String hi5Id;
@Column(name = "MOSID")
private String mosId;
.....
@MappedSuperclass
public class HBaseIdCreateTime extends HBaseId implements BaseIdCreateTime {
@Basic
@Column(name = "CREATETIME")
private long createTime;
.....
@MappedSuperclass
public class HBaseId extends BaseObject implements BaseId, Serializable{
@Id
@Column(name = "JDOID")
@GeneratedValue
private Long id;
@Version
@Column(name = "JDOVERSION")
private long jdoversion;
.....
Jeremy Bauer wrote:
> Hi Fernando,
>
> Is TeamFan also defined as an entity and is there an inheritance
> strategy defined for the Fan - TeamFan hierarchy? If not, you'll need
> to make sure you have a valid JPA inheritance hierarchy & strategy.
> If this is the case, could you post your entity classes or even
> better, a failing test case?
>
> -Jeremy
Re: having issues with first query.
Posted by Jeremy Bauer <te...@gmail.com>.
Hi Fernando,
Is TeamFan also defined as an entity and is there an inheritance
strategy defined for the Fan - TeamFan hierarchy? If not, you'll need
to make sure you have a valid JPA inheritance hierarchy & strategy.
If this is the case, could you post your entity classes or even
better, a failing test case?
-Jeremy