You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by nicolas13 <ni...@dmailer.com> on 2010/08/11 16:53:07 UTC
Cannot get primary key value (mysql)
Hello,
i've created a couple of entities with Eclipse's dali jpa tools, from my
Mysql (5.0.77) Database, with mysql 5.1.13 JDBC conenctor The issue is that
i can get the values of every column except the primary key (autoincremented
int 11). Can anyone please help me ? thanks
i'm using openjpa 2.0.0
Entity code:
@Entity
@Table(name="SOF_MIGRATION")
public class SofMigration implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(unique=true, nullable=false)
private int idMigration;
private int consumedMigration;
@Column(nullable=false, length=256)
private String emailMigration;
@Column(nullable=false, length=256)
private String pwdMigration;
public SofMigration() {
}
//snip getters and settings
}
Broker:
Query q = em.createQuery("SELECT mig FROM SofMigration mig");
--
View this message in context: http://openjpa.208410.n2.nabble.com/Cannot-get-primary-key-value-mysql-tp5412600p5412600.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Cannot get primary key value (mysql)
Posted by Rick Curtis <cu...@gmail.com>.
I haven't tried recreating this yet... but what happens if you remove the
@Column(unique=true, nullable=false) from your idMigration column?
On Thu, Aug 12, 2010 at 11:18 AM, manuu <eg...@gmail.com> wrote:
>
> Hi,
> I'm trying to resolve the same behavior. It just don't print the value of
> the column specified with @Id. I'm also using the engine
> 5.4.3-beta-community and mysql-connector-java-5.1.13
>
> I reduced my code to a simple select query execution and I'd like to add
> that I found that- in my case at least - if you move the @Id annotation
> from
> idMigration over any other column like emailMigration (folllowing the
> example presented by Nicolas) it shows the value of idMigration but
> suddenly
> stop showing the value of emailMigration.
>
> I didn't found anything useful in traces (DefaultLevel=TRACE,
> Runtime=TRACE,
> Tool=TRACE, SQL=TRACE).
>
> Thanks for posting the problem.
>
> Best regards,
> Emmanuel.
> --
>
Re: Cannot get primary key value (mysql)
Posted by manuu <eg...@gmail.com>.
Hi,
I'm trying to resolve the same behavior. It just don't print the value of
the column specified with @Id. I'm also using the engine
5.4.3-beta-community and mysql-connector-java-5.1.13
I reduced my code to a simple select query execution and I'd like to add
that I found that- in my case at least - if you move the @Id annotation from
idMigration over any other column like emailMigration (folllowing the
example presented by Nicolas) it shows the value of idMigration but suddenly
stop showing the value of emailMigration.
I didn't found anything useful in traces (DefaultLevel=TRACE, Runtime=TRACE,
Tool=TRACE, SQL=TRACE).
Thanks for posting the problem.
Best regards,
Emmanuel.
--
View this message in context: http://openjpa.208410.n2.nabble.com/Cannot-get-primary-key-value-mysql-tp5412600p5416820.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Cannot get primary key value (mysql)
Posted by nicolas13 <ni...@dmailer.com>.
>I'm going to ask the obvious....
as you guessed, i'm a newbe... your question is legitimate :-)
>but is the id column in your db named idMigration?
Yep.
The strange thing (to me, i guess there must be a obvious reason i'm failing
to understand) is that if i put the @Id annotation on another field of my
entity, specifying the column like that:
-------------------------------
@Id
@Column(name="idMigration")
private int id;
private int idMigration;
------------------------------
it works as i expected: idMigration is loaded like a regular column.
Is there any reason why i my primary key is not loaded like the other
fields?
thanks for you help.
>Another thing, I see you are using @GeneratedValue(strategy=
>GenerationType.AUTO) for your id... but I assume you want to use the MySQL
>AUTO_INCREMENT function? If so, change GenerationType.AUTO to
>GenerationType.IDENTITY.
Ok, thanks for the advice.
--
View this message in context: http://openjpa.208410.n2.nabble.com/Cannot-get-primary-key-value-mysql-tp5412600p5416352.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Cannot get primary key value (mysql)
Posted by Rick Curtis <cu...@gmail.com>.
I'm going to ask the obvious.... but is the id column in your db named
idMigration?
Another thing, I see you are using @GeneratedValue(strategy=
GenerationType.AUTO) for your id... but I assume you want to use the MySQL
AUTO_INCREMENT function? If so, change GenerationType.AUTO to
GenerationType.IDENTITY.
hth,
Rick
On Thu, Aug 12, 2010 at 3:07 AM, nicolas13 <ni...@dmailer.com> wrote:
>
> nothing special with the SQL logs, idMigration is queried.
>
> 6314 TestPlan TRACE [btpool0-0] openjpa.jdbc.SQL - <t 15926420, conn
> 16632831> executing prepstmnt 21406988 SELECT t0.idMigration,
> t0.consumedMigration, t0.emailMigration, t0.pwdMigration FROM SOF_MIGRATION
> t0
> 6315 TestPlan TRACE [btpool0-0] openjpa.jdbc.SQL - <t 15926420, conn
> 16632831> [1 ms] spent
>
Re: Cannot get primary key value (mysql)
Posted by nicolas13 <ni...@dmailer.com>.
nothing special with the SQL logs, idMigration is queried.
6314 TestPlan TRACE [btpool0-0] openjpa.jdbc.SQL - <t 15926420, conn
16632831> executing prepstmnt 21406988 SELECT t0.idMigration,
t0.consumedMigration, t0.emailMigration, t0.pwdMigration FROM SOF_MIGRATION
t0
6315 TestPlan TRACE [btpool0-0] openjpa.jdbc.SQL - <t 15926420, conn
16632831> [1 ms] spent
--
View this message in context: http://openjpa.208410.n2.nabble.com/Cannot-get-primary-key-value-mysql-tp5412600p5415269.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Cannot get primary key value (mysql)
Posted by nicolas13 <ni...@dmailer.com>.
I just want to read the data from the database, no insert/update.
I'll try with the traces, and get back here with more info.
Thanks
--
View this message in context: http://openjpa.208410.n2.nabble.com/Cannot-get-primary-key-value-mysql-tp5412600p5413035.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Cannot get primary key value (mysql)
Posted by Rick Curtis <cu...@gmail.com>.
What the the scenario that you are having problems with? Did you persist and
flush/commit any of the SofMigration Entities? Since they are generated ids
I don't think they'll be in the Entity till you put it in the DB.
Perhaps turning on SQL trace openjpa.Log=SQL=trace will shed some light as
to what is going on.
Thanks,
Rick
On Wed, Aug 11, 2010 at 9:53 AM, nicolas13 <ni...@dmailer.com> wrote:
>
> Hello,
>
> i've created a couple of entities with Eclipse's dali jpa tools, from my
> Mysql (5.0.77) Database, with mysql 5.1.13 JDBC conenctor The issue is
> that
> i can get the values of every column except the primary key
> (autoincremented
> int 11). Can anyone please help me ? thanks
>
> i'm using openjpa 2.0.0
>
> Entity code:
> @Entity
> @Table(name="SOF_MIGRATION")
> public class SofMigration implements Serializable {
> private static final long serialVersionUID = 1L;
>
> @Id
> @GeneratedValue(strategy=GenerationType.AUTO)
> @Column(unique=true, nullable=false)
> private int idMigration;
>
> private int consumedMigration;
>
> @Column(nullable=false, length=256)
> private String emailMigration;
>
> @Column(nullable=false, length=256)
> private String pwdMigration;
>
> public SofMigration() {
> }
>
> //snip getters and settings
>
> }
>
> Broker:
> Query q = em.createQuery("SELECT mig FROM SofMigration mig");
>