Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 75763 invoked from network); 7 Aug 2008 14:52:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Aug 2008 14:52:40 -0000 Received: (qmail 62425 invoked by uid 500); 7 Aug 2008 14:52:39 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 62402 invoked by uid 500); 7 Aug 2008 14:52:39 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 62391 invoked by uid 99); 7 Aug 2008 14:52:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Aug 2008 07:52:39 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists+1214986160035-208411@n2.nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Aug 2008 14:51:41 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1KR6qW-00078q-QI for users@openjpa.apache.org; Thu, 07 Aug 2008 07:52:08 -0700 Message-ID: <1218120728797-678768.post@n2.nabble.com> Date: Thu, 7 Aug 2008 07:52:08 -0700 (PDT) From: Pinaki Poddar To: users@openjpa.apache.org Subject: Re: How to apply creation timestamp with -> UNRESOLVED In-Reply-To: <489ABF28.2000507@marcelruff.info> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: ppoddar@apache.org References: <489819EA.90305@marcelruff.info> <1217978105897-674789.post@n2.nabble.com> <111276.61826.qm@web55815.mail.re3.yahoo.com> <1218045005276-676450.post@n2.nabble.com> <489AAED4.1010305@marcelruff.info> <489ABF28.2000507@marcelruff.info> X-Virus-Checked: Checked by ClamAV on apache.org OpenJPA should be able to fetch the value for the auto-assigned field after commit like any other field. The following simple test demonstrates when an auto-assigned value is set on the persistent entity when a corresponding field is declared as @Column(name="ts", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP") private Timestamp ts; /** * When does the value of an auto-assigned field gets set on the entity? */ public void testAutoAssignedFieldValue() { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); AutoInc pc = new AutoInc(); assertNull(pc.getTimestamp()); em.persist(pc); assertNull(pc.getTimestamp()); em.flush(); assertNull(pc.getTimestamp()); em.getTransaction().commit(); assertNull(pc.getTimestamp()); em.clear(); assertNull(pc.getTimestamp()); em.getTransaction().begin(); pc = em.find(AutoInc.class, pc.getId()); assertNotNull(pc); assertNotNull(pc.getTimestamp()); } Marcel Ruff wrote: > > Hi, > > i was to quickly happy: > > The timestamp is add nicely to the DB: OK > (check with normal sql) > > But when i want to load it later into my bean > it remains null in java: > CompanyProperty cp = em.find(CompanyProperty.class, key); > log.info(cp.getCreationTs()); > --> is null! > > Why this? > > Thanks > Marcel > > Marcel Ruff wrote: >> Pinaki Poddar wrote: >>> Hi, >>> With MySQL this is what happens: >>> >>> >>> 1. Definition of a column with default timestamp value >>> >>> @Column(name="ts", columnDefinition="TIMESTAMP DEFAULT >>> CURRENT_TIMESTAMP") >>> private Timestamp ts; >>> >>> 2. OpenJPA issues SQL to create the table: >>> >>> CREATE TABLE AutoInc (id BIGINT NOT NULL, ts TIMESTAMP DEFAULT >>> CURRENT_TIMESTAMP, PRIMARY KEY (id)) >>> >>> 3. OpenJPA issues SQL for insert when application does not set the >>> value of >>> ts field: >>> INSERT INTO AutoInc (id, ts) VALUES (?, ?) [params=(long) >>> 100, (null) >>> null] >>> >>> >>> 4. This is what database looks like: >>> >>> mysql> select * from autoinc; >>> +-----+---------------------+ >>> | id | ts | >>> +-----+---------------------+ >>> | 100 | 2008-08-06 12:47:29 | >>> +-----+---------------------+ >>> >> Hi all, >> >> thanks for all support & solution. >> >> For postgres 8.3.x this works well: >> >> @Column(name = "creationts", insertable=false, updatable=false, >> columnDefinition="timestamp not null default current_timestamp") >> >> >> regards >> Marcel >> >> > > > -- > Marcel Ruff > http://www.xmlBlaster.org > http://watchee.net > Phone: +49 7551 309371 > > > -- View this message in context: http://n2.nabble.com/How-to-apply-creation-timestamp-with-tp673210p678768.html Sent from the OpenJPA Users mailing list archive at Nabble.com.