You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by llchen <ll...@sympatico.ca> on 2010/07/12 15:50:57 UTC
JPA genereates non-exist id column in the select statement
I have the following entities:
@Entity
@Table(name="TDTGO")
@SecondaryTable(name="TDTGOR",
pkJoinColumns={@PrimaryKeyJoinColumn(name="DTG_OBJ_ID")})
public class VoDocumentTemplateGroupObjectData implements Serializable {
@Id
@Column(name="DTG_OBJ_ID")
protected int documentTemplateGroupObjectIdentifier;
@Column(name="DTG_OBJ_VNBR")
protected int documentTemplateGroupObjectVersionNumber;
@Column(name="DTG_OBJ_TCD", length=4)
protected String documentTemplateGroupObjectTypeCode;
...
@OneToMany
@ElementForeignKey
@ElementJoinColumns({@ElementJoinColumn(name="DTG_OBJ_TCD"),
@ElementJoinColumn(name="PARA_ID",
referencedColumnName="DTG_OBJ_ID"),
@ElementJoinColumn(name="PARA_VNBR",
referencedColumnName="DTG_OBJ_VNBR")})
protected Collection<VoParagraphData> paraObjects;
...
}
@Entity
@Table(name="TPARA")
public class VoParagraphData implements Serializable {
@Column(name="PARA_ID")
protected int paragraphIdentifier;
@Column(name="PARA_VNBR")
protected int paragraphVersionNumber;
@Column(name="DTG_OBJ_TCD", length=4)
...
}
I always got the following SQL error:
<openjpa-1.1.0-r422266:657916 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: DB2 SQL error: SQLCODE:
-206, SQLSTATE: 42703, SQLERRMC: T0.ID {prepstmnt 31 SELECT t0.id,
t0.DTG_OBJ_TCD, t0.PARA_ID, t0.PARA_TCD, t0.PARA_VNBR FROM LLLTUO#2.TPARA
t0 INNER JOIN LLLTUO#2.TDTGO t1 ON t0.DTG_OBJ_TCD = t1.DTG_OBJ_TCD AND
t0.PARA_ID = t1.DTG_OBJ_ID AND t0.PARA_VNBR = t1.DTG_OBJ_VNBR WHERE
t1.DTG_OBJ_ID = ? [params=(int) 3009]} [code=-206, state=42703]SQLCA
OUTPUT[Errp=DSNXORSO, Errd=-600, 0, 0, -1, 0, 0]
There is no ID column in any of the tables and I just can't figure out why
the JPA genereates that in its SQL select statement. I badly need your help.
Thanks,
Lule
--
View this message in context: http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-the-select-statement-tp5282960p5282960.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: JPA genereates non-exist id column in the select statement
Posted by llchen <ll...@sympatico.ca>.
I gave up the OneToMany attempt due to the secondary entity does not have an
Id field. I replaced it with direct JPQL to retrieve the related collection,
thought I have to explicitly list all the fields in the select statement,
otherwise the id field will be added into the SQL select statement as well.
Thanks for your suggestions.
Lule
--
View this message in context: http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-the-select-statement-tp5282960p5293877.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: JPA genereates non-exist id column in the select statement
Posted by Fay Wang <fy...@yahoo.com>.
You can try @PersistentCollection
----- Original Message ----
From: llchen <ll...@sympatico.ca>
To: users@openjpa.apache.org
Sent: Tue, July 13, 2010 10:22:57 AM
Subject: Re: JPA genereates non-exist id column in the select statement
Sorry I forgot to mention that I am using JPA 1.0 and therefore I can't use
@ElementCollection tag.
Lule
--
View this message in context:
http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-the-select-statement-tp5282960p5288555.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: JPA genereates non-exist id column in the select statement
Posted by llchen <ll...@sympatico.ca>.
Sorry I forgot to mention that I am using JPA 1.0 and therefore I can't use
@ElementCollection tag.
Lule
--
View this message in context: http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-the-select-statement-tp5282960p5288555.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: JPA genereates non-exist id column in the select statement
Posted by Fay Wang <fy...@yahoo.com>.
Hi,
Making the superclass an embeddable should not prevent it from being
subclassed by other entities.
Regards,
Fay
----- Original Message ----
From: llchen <ll...@sympatico.ca>
To: users@openjpa.apache.org
Sent: Tue, July 13, 2010 3:42:26 AM
Subject: Re: JPA genereates non-exist id column in the select statement
Thanks for your suggestion, I will try that embedable option. But that second
entity VoVariableData actually is a super class for onother three entities.
If I make that one into a embedable, then the other three will not be able
to subclass from it.
Lule
--
View this message in context:
http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-the-select-statement-tp5282960p5286901.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: JPA genereates non-exist id column in the select statement
Posted by llchen <ll...@sympatico.ca>.
Thanks for your suggestion, I will try that embedable option. But that second
entity VoVariableData actually is a super class for onother three entities.
If I make that one into a embedable, then the other three will not be able
to subclass from it.
Lule
--
View this message in context: http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-the-select-statement-tp5282960p5286901.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: JPA genereates non-exist id column in the select statement
Posted by Fay Wang <fy...@yahoo.com>.
Sorry, I have mistakenly copied and pasted the wrong annotations for the
collection of VoParagraphData. Here is the correct annotation for it:
@ElementCollection
@CollectionTable(name="TPARA",
joinColumns={
@JoinColumn(name="PARA_ID", referencedColumnName="DTG_OBJ_ID"),
@JoinColumn(name="PARA_VNBR", referencedColumnName="DTG_OBJ_VNBR")
}
)
protected Collection<VoParagraphData> paraObjects;
----- Original Message ----
From: Fay Wang <fy...@yahoo.com>
To: users@openjpa.apache.org
Sent: Mon, July 12, 2010 4:09:31 PM
Subject: Re: JPA genereates non-exist id column in the select statement
Since the underlying table does not have primary key, you might want to make
VoParagraphData an embeddable:
@Embeddable
public class VoParagraphData implements Serializable {
In the VoDocumentTemplateGroupObjectData, you can make the collection of
VoParagraphData an ElementCollection:
@ElementJoinColumn(name="PARA_VNBR",referencedColumnName="DTG_OBJ_VNBR")})
@ElementCollection
@CollectionTable(name="TPARA",
joinColumns={
@JoinColumn(name="PARA_ID", referencedColumnName="DTG_OBJ_ID"),
@JoinColumn(name="PARA_VNBR", referencedColumnName="DTG_OBJ_VNBR")
}
)
protected Collection<VoParagraphData> paraObjects;
----- Original Message ----
From: llchen <ll...@sympatico.ca>
To: users@openjpa.apache.org
Sent: Mon, July 12, 2010 3:51:45 PM
Subject: RE: JPA genereates non-exist id column in the select statement
Thanks for promptly replying. But how do I handle the entity without a
primary key as the underline table does not have one? Set up a fake primary
key in the entity or what?
Lule
_____
From: Rick Curtis [via OpenJPA]
[mailto:ml-node+5283244-1458393612-586565@n2.nabble.com]
Sent: Monday, July 12, 2010 10:53 AM
To: llchen
Subject: Re: JPA genereates non-exist id column in the select statement
Section 2.4 of the 2.0 spec states "Every entity must have a primary key."
I seem to remember that OpenJPA will do some magic when we enhance your
Entities if we don't find an @Id column... I don't have time to try this am,
but I'd be willing to bet that is what's going on.
tht,
Rick
_____
View message @
http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-th
e-select-statement-tp5282960p5283244.html
To unsubscribe from JPA genereates non-exist id column in the select
statement, click
< (link removed)
aGVuQHN5bXBhdGljby5jYXw1MjgyOTYwfDIzMDMwNjc3MQ==> here.
--
View this message in context:
http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-the-select-statement-tp5282960p5285218.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: JPA genereates non-exist id column in the select statement
Posted by Fay Wang <fy...@yahoo.com>.
Since the underlying table does not have primary key, you might want to make
VoParagraphData an embeddable:
@Embeddable
public class VoParagraphData implements Serializable {
In the VoDocumentTemplateGroupObjectData, you can make the collection of
VoParagraphData an ElementCollection:
@ElementJoinColumn(name="PARA_VNBR",referencedColumnName="DTG_OBJ_VNBR")})
@ElementCollection
@CollectionTable(name="TPARA",
joinColumns={
@JoinColumn(name="PARA_ID", referencedColumnName="DTG_OBJ_ID"),
@JoinColumn(name="PARA_VNBR", referencedColumnName="DTG_OBJ_VNBR")
}
)
protected Collection<VoParagraphData> paraObjects;
----- Original Message ----
From: llchen <ll...@sympatico.ca>
To: users@openjpa.apache.org
Sent: Mon, July 12, 2010 3:51:45 PM
Subject: RE: JPA genereates non-exist id column in the select statement
Thanks for promptly replying. But how do I handle the entity without a
primary key as the underline table does not have one? Set up a fake primary
key in the entity or what?
Lule
_____
From: Rick Curtis [via OpenJPA]
[mailto:ml-node+5283244-1458393612-586565@n2.nabble.com]
Sent: Monday, July 12, 2010 10:53 AM
To: llchen
Subject: Re: JPA genereates non-exist id column in the select statement
Section 2.4 of the 2.0 spec states "Every entity must have a primary key."
I seem to remember that OpenJPA will do some magic when we enhance your
Entities if we don't find an @Id column... I don't have time to try this am,
but I'd be willing to bet that is what's going on.
tht,
Rick
_____
View message @
http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-th
e-select-statement-tp5282960p5283244.html
To unsubscribe from JPA genereates non-exist id column in the select
statement, click
< (link removed)
aGVuQHN5bXBhdGljby5jYXw1MjgyOTYwfDIzMDMwNjc3MQ==> here.
--
View this message in context:
http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-the-select-statement-tp5282960p5285218.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
RE: JPA genereates non-exist id column in the select statement
Posted by llchen <ll...@sympatico.ca>.
Thanks for promptly replying. But how do I handle the entity without a
primary key as the underline table does not have one? Set up a fake primary
key in the entity or what?
Lule
_____
From: Rick Curtis [via OpenJPA]
[mailto:ml-node+5283244-1458393612-586565@n2.nabble.com]
Sent: Monday, July 12, 2010 10:53 AM
To: llchen
Subject: Re: JPA genereates non-exist id column in the select statement
Section 2.4 of the 2.0 spec states "Every entity must have a primary key."
I seem to remember that OpenJPA will do some magic when we enhance your
Entities if we don't find an @Id column... I don't have time to try this am,
but I'd be willing to bet that is what's going on.
tht,
Rick
_____
View message @
http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-th
e-select-statement-tp5282960p5283244.html
To unsubscribe from JPA genereates non-exist id column in the select
statement, click
< (link removed)
aGVuQHN5bXBhdGljby5jYXw1MjgyOTYwfDIzMDMwNjc3MQ==> here.
--
View this message in context: http://openjpa.208410.n2.nabble.com/JPA-genereates-non-exist-id-column-in-the-select-statement-tp5282960p5285218.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: JPA genereates non-exist id column in the select statement
Posted by Rick Curtis <cu...@gmail.com>.
Section 2.4 of the 2.0 spec states "Every entity must have a primary key."
I seem to remember that OpenJPA will do some magic when we enhance your
Entities if we don't find an @Id column... I don't have time to try this am,
but I'd be willing to bet that is what's going on.
tht,
Rick