Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 87877 invoked from network); 1 Apr 2008 16:45:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Apr 2008 16:45:38 -0000 Received: (qmail 23143 invoked by uid 500); 1 Apr 2008 16:45:38 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 22984 invoked by uid 500); 1 Apr 2008 16:45:37 -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 22975 invoked by uid 99); 1 Apr 2008 16:45:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Apr 2008 09:45:37 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of plinskey@gmail.com designates 209.85.142.189 as permitted sender) Received: from [209.85.142.189] (HELO ti-out-0910.google.com) (209.85.142.189) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Apr 2008 16:44:57 +0000 Received: by ti-out-0910.google.com with SMTP id y6so849725tia.13 for ; Tue, 01 Apr 2008 09:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=mYDlWe++GhIi6YNQaiPSpfNOcFzIDgOJLukR/QpGTj8=; b=G+v/WE6+i448j2s0kGViaTQpry5pj+v1mwF/eCqH4p5H7NfuKgldeZXS+yi/VptcbCKCeZZF+nLdAhnU5eOer/NPDpGGLw6ee5f/WCCA/w4PI/WOQSt/Si5QqzhK1Q+JDkXEKLyqCZA6blVhxoU65xH18uNPxbNezZvPQRHtQwM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ty5rIRYJpLGged32HJTTCfHBjz1IPuyrm+48dduxkSEOF9sijsWRWfLGHGdGWux2eY7RfL5GzAxKIn1OAmDBEmxd2Pro0k3wc/2n0NGQ8Tf84y8PgeIx4Bsk7MiMKzHzZdFU4J356Y3dnb40Q1LDf2qcbxUwEpKvWEfg8RDwoQY= Received: by 10.151.150.13 with SMTP id c13mr862547ybo.168.1207068307115; Tue, 01 Apr 2008 09:45:07 -0700 (PDT) Received: by 10.150.158.20 with HTTP; Tue, 1 Apr 2008 09:45:07 -0700 (PDT) Message-ID: <7262f25e0804010945p43f749b5j37c739f4cc893ec5@mail.gmail.com> Date: Tue, 1 Apr 2008 09:45:07 -0700 From: "Patrick Linskey" To: users@openjpa.apache.org Subject: Re: How to diagnose rather cryptic error messages In-Reply-To: <200804011731.35772.david.goodenough@btconnect.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200804011504.04266.david.goodenough@btconnect.com> <7262f25e0804010844v3cb2200u6898be17ebea3b48@mail.gmail.com> <200804011731.35772.david.goodenough@btconnect.com> X-Virus-Checked: Checked by ClamAV on apache.org > Also why does the persist apparently work? Should it now throw an > exception if it is used out of a transaction? Because this is valid in some contexts (extended persistence contexts): em.persist(new User()); em.getTransaction().begin(); em.getTransaction().commit(); > To be honest my first code has cascade=CascadeType.ALL just about > everwhere, until I get into more details. Note that this can be dangerous -- CascadeType.REMOVE means that if you delete an instance, its so-marked related instances will be deleted also. -Patrick On Tue, Apr 1, 2008 at 9:31 AM, David Goodenough wrote: > On Tuesday 01 April 2008, Patrick Linskey wrote: > > > Does a persist have to be inside a Transaction? > > > > In short, yes -- changes will only get written back to the database > > within a transaction. IIRC, if you call persist() outside a > > transaction and then begin and commit one, the new objects will be > > written also. > Can I suggest that the manual could be clearer here. In section 8.2 > on page 65 it is not obvious whether the comment just above the > code box for remove applies to the persist or remove methods. > > Also why does the persist apparently work? Should it now throw an > exception if it is used out of a transaction? > > > > > > Then create a User object, which amongst other things has a List of > > > Role objects in it, so I add the Role object I just create to it, fill > > > in all the other fields, and try to persist it. > > > > Bear in mind that one of the interesting "features" of the JPA > > specification is that when you have a persistent relationship, you > > need to either put a 'cascade=CascadeType.PERSIST' (or equivalent) > > into the annotation on the relationship, or manually call persist() on > > related data, or set the cascade-persist default override switch in > > your orm.xml. (Yes, I agree that this is more complicated than it > > should be; this is just a warning.) > To be honest my first code has cascade=CascadeType.ALL just about > everwhere, until I get into more details. > > David > > > > > > > I get back an exception which says:- > > > > > > Exception in thread "main" > > error> org.apache.openjpa.persistence.PersistenceException: null > > > > That's definitely not a great error. > > > > -Patrick > > > > On Tue, Apr 1, 2008 at 7:04 AM, David Goodenough > > > > wrote: > > > I am relatively new to JPA, and trying to get to grips with what I can > > > and can not do with it. > > > > > > So I thought I would try creating a small system (which will grow) which > > > has amongst other things User objects and Role objects in it. > > > > > > OpenJPA has successfully taken my list of Entities and created the > > > relevant tables. The Entity classes have all been enhanced. I am using > > > OpenJPA 1.0.2. > > > > > > I create a Role object (which does not contain a reference to other > > > objects) and persist it. No errors are reported, but the object does > > > not appear as a record in the DB. Does a persist have to be inside > > > a Transaction? The manual is confusing as it says that "this action can > > > only be performed in the context of an active transaction" right at the > > > end of the description of persist, but I read it (given the way it was > > > laid out) to apply to the remove action which immediately follows it. > > > > > > Then create a User object, which amongst other things has a List of > > > Role objects in it, so I add the Role object I just create to it, fill > > > in all the other fields, and try to persist it. > > > > > > I get back an exception which says:- > > > > > > Exception in thread "main" > > error> org.apache.openjpa.persistence.PersistenceException: null > > > at > > > > > > org.apache.openjpa.meta.ProxySetupStateManager.providedStringField(ProxyS > > >etupStateManager.java:234) at > > > uk.co.dga.bm.jpa.User.pcProvideField(User.java) > > > at > > > > > > org.apache.openjpa.meta.ProxySetupStateManager.setProxyData(ProxySetupSta > > >teManager.java:58) at > > > > > > org.apache.openjpa.meta.ClassMetaData.resolveMeta(ClassMetaData.java:1731 > > >) at > > > org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1613) > > > at > > > > > > org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataReposito > > >ry.java:675) at > > > > > > org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository > > >.java:575) at > > > > > > org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.jav > > >a:500) at > > > > > > org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository > > >.java:302) at > > > org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2372) at > > > org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2225) at > > > > > > org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java: > > >1005) at > > > > > > org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImp > > >l.java:541) at uk.co.dga.bm.loader.CreateUser.run(CreateUser.java:34) at > > > uk.co.dga.bm.loader.CreateUser.main(CreateUser.java:41) > > > > > > which is not very helpful. How do I get more information on exactly > > > what it is trying to do so that I can fix it? > > > > > > David > -- Patrick Linskey 202 669 5907