Re: "Can't get primary key from temporary id" :(

2009-04-23 Thread Joseph Schmidt
No if one is doing with DB directly or with JDBC, the following will work: -- start transaction INSERT INTO t_1 (name) VALUES ('name1'); INSERT INTO t_1 (name) VALUES ('name2'); INSERT INTO t_2 (name,t_1_id) select 'name1' , t_1.id from t_1 where t_1.name='name1'; commit; -- end transaction

Re: "Can't get primary key from temporary id" :(

2009-04-22 Thread Aristedes Maniatis
On 23/04/2009, at 12:53 AM, Joseph Schmidt wrote: Of course I demonstrated. The snippet in the parent just works with MySQL (with InnoDB of course). There's no need for a last_insert_id(), since the PK are "autoincrement". Inside the same transaction, the consequent selects will simply pic

Re: "Can't get primary key from temporary id" :(

2009-04-22 Thread Mike Kienenberger
Might be a long shot, but if you start a root transaction at the start of PrePersist and then commit it in PostPersist, maybe that will work. On Wed, Apr 22, 2009 at 12:57 PM, Joseph Schmidt wrote: >>  You might also take a look at the 3.0 lifecycles that Ari mentioned >> in the issue, but my gue

Re: "Can't get primary key from temporary id" :(

2009-04-22 Thread Joseph Schmidt
You might also take a look at the 3.0 lifecycles that Ari mentioned in the issue, but my guess is that JPA lifecycles won't do what is needed. I did. To be inside the same transaction for writing, PrePersist would be the logical choice (from what I understood the docs). The very short document

Re: "Can't get primary key from temporary id" :(

2009-04-22 Thread Mike Kienenberger
I've done auditing a couple of ways in the past. The first time, in Cayenne 1.1, I did it at the application level using customized entity templates and setAndLog() methods instead of set() methods. It wasn't ideal, and it didn't work for many-to-many joins (never had any many-to-manys back the

Re: "Can't get primary key from temporary id" :(

2009-04-22 Thread Michael Gentry
FWIW, we are planning on filling in our Audit table using triggers on the tables we care about auditing. This will also capture changes made outside of Cayenne. On Wed, Apr 22, 2009 at 10:53 AM, Joseph Schmidt wrote: > >>> I'd be interested in hearing what others have to say... feasible given >>

Re: "Can't get primary key from temporary id" :(

2009-04-22 Thread Joseph Schmidt
I'd be interested in hearing what others have to say... feasible given the current cayenne stack? The problem is that the original poster is trying to use Cayenne like he uses pure SQL and No, I'm not. Like I mentioned in earlier posts, I'm using ObjRelationships and all the Cayenne goodie

Re: "Can't get primary key from temporary id" :(

2009-04-21 Thread Aristedes Maniatis
On 22/04/2009, at 2:58 AM, Robert Zeigler wrote: Hm have you considered using runtime relationships? (NOTE: I've never played with this, myself, so take the next bit with a grain of salt. :) In theory, it's entirely possible with cayenne to have a single generic data object and then mo

Re: "Can't get primary key from temporary id" :(

2009-04-21 Thread Robert Zeigler
Hm have you considered using runtime relationships? (NOTE: I've never played with this, myself, so take the next bit with a grain of salt. :) In theory, it's entirely possible with cayenne to have a single generic data object and then modify the mapping information at runtime as necessa

Re: "Can't get primary key from temporary id" :(

2009-04-21 Thread Joseph Schmidt
Hm. You're defining a relationship; I've always mapped relationships aas relationships, and let Cayenne deal with the id specifics. Note that cayenne won't force the creation foreign key (although you should create one, if your db supports it). You say you have "too many tables like that"...

Re: "Can't get primary key from temporary id" :(

2009-04-21 Thread Robert Zeigler
Hm. You're defining a relationship; I've always mapped relationships aas relationships, and let Cayenne deal with the id specifics. Note that cayenne won't force the creation foreign key (although you should create one, if your db supports it). You say you have "too many tables like that".

Re: "Can't get primary key from temporary id" :(

2009-04-20 Thread Joseph Schmidt
* write the record to database, fetch it back again and then you'll have the primary key Than this is not the same transaction :(. Correct. This is a limitation of how databases work, not Cayenne. You can't have a primary key until you write the record, unless you do something tricky like u

Re: "Can't get primary key from temporary id" :(

2009-04-08 Thread Joseph Schmidt
> It sounds like you are trying to > write a record into a log/audit > table.  Yes, for some entities it is some sort of high level audit, and for others it is a recent activity table. > Have you looked at MySQL triggers to do > this?  The advantage > of using a trigger is that even if someone c

Re: "Can't get primary key from temporary id" :(

2009-04-08 Thread Michael Gentry
I would only be semi-comfortable exposing a primary key if it were encrypted by a private key that changed per-session. Just my thoughts... mrg On Tue, Apr 7, 2009 at 9:03 PM, Joseph Schmidt wrote: > >> > Can't get primary key from temporary id >> > >&g

Re: "Can't get primary key from temporary id" :(

2009-04-07 Thread Tore Halset
On Apr 8, 2009, at 3:28 , Aristedes Maniatis wrote: On 08/04/2009, at 11:03 AM, Joseph Schmidt wrote: * write the record to database, fetch it back again and then you'll have the primary key Than this is not the same transaction :(. Correct. This is a limitation of how databases work, not C

Re: "Can't get primary key from temporary id" :(

2009-04-07 Thread Aristedes Maniatis
On 08/04/2009, at 11:03 AM, Joseph Schmidt wrote: * write the record to database, fetch it back again and then you'll have the primary key Than this is not the same transaction :(. Correct. This is a limitation of how databases work, not Cayenne. You can't have a primary key until you writ

Re: "Can't get primary key from temporary id" :(

2009-04-07 Thread Joseph Schmidt
> > Can't get primary key from temporary id > > > > > > while trying to access the 'id' of a newly created > object entity A. > > I need this 'id' to write the value together with some > > other fields in some other

Re: "Can't get primary key from temporary id" :(

2009-04-07 Thread Aristedes Maniatis
On 08/04/2009, at 8:26 AM, Joseph Schmidt wrote: Can't get primary key from temporary id while trying to access the 'id' of a newly created object entity A. I need this 'id' to write the value together with some other fields in some other object

"Can't get primary key from temporary id" :(

2009-04-07 Thread Joseph Schmidt
I'm getting the following error: Can't get primary key from temporary id while trying to access the 'id' of a newly created object entity A. I need this 'id' to write the value together with some other fields in some other object entity