Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 75077D09B for ; Mon, 19 Nov 2012 18:27:36 +0000 (UTC) Received: (qmail 86238 invoked by uid 500); 19 Nov 2012 18:27:36 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 86196 invoked by uid 500); 19 Nov 2012 18:27:36 -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 86188 invoked by uid 99); 19 Nov 2012 18:27:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Nov 2012 18:27:36 +0000 X-ASF-Spam-Status: No, hits=1.6 required=5.0 tests=FREEMAIL_REPLY,RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of cwolf.algo@gmail.com designates 209.85.216.174 as permitted sender) Received: from [209.85.216.174] (HELO mail-qc0-f174.google.com) (209.85.216.174) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Nov 2012 18:27:31 +0000 Received: by mail-qc0-f174.google.com with SMTP id o22so3928386qcr.33 for ; Mon, 19 Nov 2012 10:27:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=zedszP2NTK/QcWRmcaEIt3N0VA6UjRZMUD+m0E0NSfs=; b=M/v8Ct4SLuKfEv2GA63y1pesz4KnK4yuMDPVoc7N+uBQKGtmHJ1N1HhzJYIEMt5Wbr N7iE8OzzpLbyHqWOC/gv9BV8iznnSgEx3CY6vro7PqqJ/mLOhSkDQXTZjWNBOWyRVrmh tEi0NW+yoGOJ2VYmUJoxc9zriDkKAsi1Z3dXaHVvq5QCUrr+NuDMdPn5XmNAAar0/R+m 1J8POespFHNgtw0FUmbkU626fwgCNPzcR8TxXJ2DO3BBfTFkwFWNhP8AlY9Bu9I5z+cO 764wDiEJ6TyyBVr8SV/WjrCYCfrnP5eoyBP8KVudqOBYOjJWCHRUuC4ZqOjVX3507/Sq xDiQ== MIME-Version: 1.0 Received: by 10.224.186.17 with SMTP id cq17mr12481884qab.83.1353349630693; Mon, 19 Nov 2012 10:27:10 -0800 (PST) Received: by 10.49.58.230 with HTTP; Mon, 19 Nov 2012 10:27:10 -0800 (PST) In-Reply-To: References: Date: Mon, 19 Nov 2012 13:27:10 -0500 Message-ID: Subject: Re: cannot persist m2m data, getting "ArgumentException: Attempt to cast instance xxx [java.util.HashSet]" to PersistenceCapable failed. Ensure that it has been enhanced." From: Chris Wolf To: users@openjpa.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Rick, I know this is sick and wrong - but I sub-classed java.util.HashSet such that I was able to enhance that subclass and used it for my concrete collection field instances. Basically, I just did this: @Entity public class ORMHashSet extends HashSet {/* constructors */} I finally got rid of that annoying "Attempt to cast instance xxx [java.util.HashSet]" to PersistenceCapable failed." error, but now - a new problem (at least it's getting as far as calling comit() on the EntityManager) Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: ORA-00942: table or view does not exist {prepstmnt 617013740 SELECT SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE ID =3D ? FOR UPDATE [params=3D?]} [code=3D942, state=3D42000] Note that my two entities have specifically named @SequenceGenerator, so this error should not be related to those. I guess my hack of annotating ORMHashSet as an Entity provoked generation of some default sequence generator? I just thought I'd try a few last desperate things before resorting to going back to using Hibernate... ;) On Mon, Nov 19, 2012 at 10:34 AM, Rick Curtis wrote: > Chris - > > Please post your persistence.xml file also. > > Thanks, > Rick > > > On Mon, Nov 19, 2012 at 9:28 AM, Chris Wolf wrote: > >> Jos=E9, >> >> The plugin doc says you can have a comma-delimited list of classes, >> however, since >> enhancement on collection classes doesn't seem to work anyway - per >> your suggestion, >> I removed "java.util.ArrayList" and re-ran the "mvn openjpa:enhance" >> command. >> >> The result, as ever, is still: >> >> 771 openjpa INFO [main] openjpa.Enhance - Creating subclass and >> redefining methods for >> "[class java.util.ArrayList]". This means that your application will >> be less efficient than it would >> if you ran the OpenJPA enhancer. >> Exception in thread "main" >> org.apache.openjpa.persistence.ArgumentException: No registered >> metadata for type >> "class java.util.ArrayList". This can happen if this class has not >> been annotated as a >> persistent entity or specified in the persistence unit (ex: in the >> orm.xml). >> >> I wonder if anyone knows of a working example of many-to-many ORM using >> OpenJPA? >> >> Thanks, >> >> -Chris >> >> >> On Mon, Nov 19, 2012 at 10:19 AM, Jos=E9 Luis Cetina >> wrote: >> > And I think you don't have to set arraylist class or any java "native" >> > class as enhance class. Only your entities have to be enhancement. >> > El 19/11/2012 09:12, "Jos=E9 Luis Cetina" escri= bi=F3: >> > >> >> I'm not sure if the include tag accept more than 1 class. >> >> >> >> You have: >> >> **/entities/*.class,java.util.ArrayList.class >> >> >> >> Try to remove java.util.ArrayList. >> >> El 19/11/2012 09:05, "Chris Wolf" escribi=F3: >> >> >> >>> Jos=E9, >> >>> >> >>> Thanks - I sent the two entities to John (this list). The pom.xml i= s >> >>> attached... >> >>> >> >>> -Chris >> >>> >> >>> >> >>> >> >>> On Mon, Nov 19, 2012 at 9:54 AM, Jos=E9 Luis Cetina < >> maxtorzito@gmail.com> >> >>> wrote: >> >>> > Please send your 2 entities and your pom configuration whit the >> enhance >> >>> > plugin. >> >>> > El 19/11/2012 08:46, "Chris Wolf" escribi= =F3: >> >>> > >> >>> >> Jos=E9, >> >>> >> >> >>> >> I tried List/ArrayList - same error. Thanks.... >> >>> >> >> >>> >> -Chris >> >>> >> >> >>> >> On Sun, Nov 18, 2012 at 9:47 PM, Jos=E9 Luis Cetina < >> >>> maxtorzito@gmail.com> >> >>> >> wrote: >> >>> >> > Of course I'm using 1-M relationships but I use them with List = not >> >>> >> hashset, >> >>> >> > why you dont give a try to list only for look if the problem is >> with >> >>> >> > hashset. >> >>> >> > El 18/11/2012 19:59, "Chris Wolf" >> escribi=F3: >> >>> >> > >> >>> >> >> Jos=E9, >> >>> >> >> >> >>> >> >> Thanks for your reply. My pom.xml setup is very similar to yo= urs >> >>> and >> >>> >> >> the "enhance" goal runs without error, but, as I mentioned, >> >>> >> >> I still get the error on "casting java.util.HashSet". Are yo= u >> able >> >>> >> >> to persist entities with 1-M or M-M relationships? >> >>> >> >> >> >>> >> >> BTW, I changed my code to temporarily change JPA provider from >> >>> OpenJPA >> >>> >> >> to the Hibernate JPA provider >> >>> >> >> and, once again, Hibernate's JPA reports: >> >>> >> >> >> >>> >> >> Exception in thread "main" java.lang.IllegalArgumentException: >> >>> Unknown >> >>> >> >> entity: java.util.HashSet >> >>> >> >> at >> >>> >> >> >> >>> >> >> >>> >> org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManage= rImpl.java:671) >> >>> >> >> >> >>> >> >> Well, at least both JPA implementations are complaining about = the >> >>> same >> >>> >> >> issue - I just wish I knew >> >>> >> >> what I was doing! I know I can get this to work in an instan= t >> by >> >>> >> >> reverting to Hibernate-only >> >>> >> >> solution, but I was hoping the byte-code weaving of JPA would = be >> a >> >>> >> >> performance advantage over >> >>> >> >> Hibernate's reflection/proxy pattern. >> >>> >> >> >> >>> >> >> Thanks again, >> >>> >> >> >> >>> >> >> -Chris >> >>> >> >> >> >>> >> >> On Sun, Nov 18, 2012 at 1:26 PM, Jos=E9 Luis Cetina < >> >>> maxtorzito@gmail.com >> >>> >> > >> >>> >> >> wrote: >> >>> >> >> > I have this in my pom.xml for ENHANCMENT and works: >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > org.apache.openjpa >> >>> >> >> > openjpa-maven-plugin >> >>> >> >> > 2.2.0 >> >>> >> >> > >> >>> >> >> > >> mypackage/model/*.class >> >>> >> >> > >> >>> >> true >> >>> >> >> > >> >>> >> >> > true >> >>> >> >> > >> >>> >> >> > >> com.mysql.jdbc.Driver >> >>> >> >> > >> >>> >> >> > driverClass=3D${database.driver.name= }, >> >>> >> >> > jdbcUrl=3D${database.connection.url}= , >> >>> >> >> > user=3D${database.user}, >> >>> >> >> > password=3D${database.password}, >> >>> >> >> > minPoolSize=3D5, >> >>> >> >> > acquireRetryAttempts=3D3, >> >>> >> >> > maxPoolSize=3D20 >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > enhancer >> >>> >> >> > process-classes >> >>> >> >> > >> >>> >> >> > enhance >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > org.apache.openjpa >> >>> >> >> > openjpa >> >>> >> >> > 2.2.0 >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > In my persistence.xml i have: >> >>> >> >> > >> >>> >> >> > > >>> >> value=3D"${db.username}"/> >> >>> >> >> > > >>> >> >> value=3D"${db.password}"/> >> >>> >> >> > > value=3D"${db.url}"/> >> >>> >> >> > > >>> >> >> > value=3D"${db.driver.class}"/> >> >>> >> >> > >> >>> >> >> > You can replace the database properties in persistence.xml w= ith >> >>> your >> >>> >> own >> >>> >> >> > values >> >>> (${db.username},${db.password},${db.url},${db.driver.class}). >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > I use this configuration for my JEE Projects. >> >>> >> >> > >> >>> >> >> > Maybe this can help you. >> >>> >> >> > >> >>> >> >> > Regards. >> >>> >> >> > >> >>> >> >> > SCJA. JL Cetina >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > 2012/11/18 Chris Wolf >> >>> >> >> > >> >>> >> >> >> I wrote a shell script to directly invoke PCEnhancer on cla= ss >> >>> >> >> >> java.util.HashSet, >> >>> >> >> >> and even that didn't work: >> >>> >> >> >> >> >>> >> >> >> $ ./enhance.sh >> >>> >> >> >> 52 openjpa INFO [main] openjpa.Tool - Enhancer running = on >> >>> type >> >>> >> >> >> "java.util.HashSet". >> >>> >> >> >> Exception in thread "main" java.lang.RuntimeException: >> >>> >> >> >> java.io.FileNotFoundExcep >> >>> >> >> >> tion: file:\C:\opt\jdk\jre\lib\rt.jar!\java\util\HashSet.cl= ass >> >>> (The >> >>> >> >> >> filename, directory name, or volume label syntax is incorre= ct) >> >>> >> >> >> at >> >>> >> >> >> >> >>> >> >> >> >>> >> >> >>> >> org.apache.openjpa.lib.conf.Configurations.launchRunnable(Configurations= .java:744) >> >>> >> >> >> >> >>> >> >> >> On Sun, Nov 18, 2012 at 10:37 AM, Chris Wolf < >> >>> cwolf.algo@gmail.com> >> >>> >> >> wrote: >> >>> >> >> >> > Hello, >> >>> >> >> >> > >> >>> >> >> >> > This is my first posting and first attempt to use OpenJPA= . >> I >> >>> put >> >>> >> >> >> > together a quick demo and can persist >> >>> >> >> >> > individual, unrelated entities. However, when I try to >> persist >> >>> >> >> >> > related entities to two tables via a link table, i.e. >> >>> many-2-many, >> >>> >> >> >> > it keeps complaining about "casting to PersistenceCapable= ", >> in >> >>> >> >> >> > particular the class "java.util.HashSet". >> >>> >> >> >> > >> >>> >> >> >> > First, I am using the Eclipse JPA plugin (called "Dali" o= r >> >>> >> >> >> > "EclipseLink"). Of course, I have OpenJPA configured >> >>> >> >> >> > as my JPA provider, I am in a plain Java SE environment w= ith >> >>> >> >> >> > LOCAL_RESOURCE via JDBC connection >> >>> >> >> >> > properties in the persistence.xml. I am using Sun/Oracle >> 64bit >> >>> >> >> >> > JDK-1.6 and OpenJPA-2.2.0. >> >>> >> >> >> > >> >>> >> >> >> > I am using the Eclipse JPA plugin to generate the entity >> >>> classes >> >>> >> from >> >>> >> >> >> > already-exiting database schema objects, >> >>> >> >> >> > and that code looks like (just pasting the relationship >> code), >> >>> this >> >>> >> >> >> > action also adds these classes to persistence.xml >> >>> >> >> >> > via persistence-unit/class elements. >> >>> >> >> >> > >> >>> >> >> >> > First M2M entity, "MarketData": >> >>> >> >> >> > >> >>> >> >> >> > //bi-directional many-to-many association to >> RiskFactor >> >>> >> >> >> > @ManyToMany(mappedBy=3D"marketData") >> >>> >> >> >> > public Set getRiskFactors() { >> >>> >> >> >> > return this.riskFactors; >> >>> >> >> >> > } >> >>> >> >> >> > >> >>> >> >> >> > Second M2M entity "RiskFactor": >> >>> >> >> >> > >> >>> >> >> >> > //bi-directional many-to-many association to >> MarketData >> >>> >> >> >> > @ManyToMany >> >>> >> >> >> > @JoinTable( >> >>> >> >> >> > name=3D"MARKET_DATA__RISK_FACTOR" >> >>> >> >> >> > , joinColumns=3D{ >> >>> >> >> >> > @JoinColumn(name=3D"RISK_FACTOR_I= D", >> >>> >> >> >> nullable=3Dfalse) >> >>> >> >> >> > } >> >>> >> >> >> > , inverseJoinColumns=3D{ >> >>> >> >> >> > @JoinColumn(name=3D"MARKET_DATA_I= D", >> >>> >> >> >> nullable=3Dfalse) >> >>> >> >> >> > } >> >>> >> >> >> > ) >> >>> >> >> >> > public Set getMarketData() { >> >>> >> >> >> > return this.marketData; >> >>> >> >> >> > } >> >>> >> >> >> > >> >>> >> >> >> > When I run the code, the log indicates implicit runtime >> >>> enhacement, >> >>> >> >> >> > yet it is complaining: >> >>> >> >> >> > >> >>> >> >> >> > "[persistdemo.ojpa.entities.RiskFactor@61578aab] >> >>> >> [java.util.HashSet]" >> >>> >> >> >> > to PersistenceCapable failed. Ensure that it has been >> >>> enhanced." >> >>> >> >> >> > >> >>> >> >> >> > ...when it says, "Ensure that it has been enhanced." - >> which is >> >>> >> "it" >> >>> >> >> >> > referring to? The entity "RiskFactor" or the field >> >>> relationship >> >>> >> >> >> > field's class, "java.util.HashSet"? >> >>> >> >> >> > >> >>> >> >> >> > >> >>> >> >> >> > 186 openjpa INFO [main] openjpa.Runtime - OpenJPA >> >>> dynamically >> >>> >> >> >> > loaded the class enhancer. Any classes that were not >> enhanced >> >>> at >> >>> >> build >> >>> >> >> >> > time will be enhanced when they are loaded by the JVM. >> >>> >> >> >> > SLF4J: Failed to load class >> >>> "org.slf4j.impl.StaticLoggerBinder". >> >>> >> >> >> > SLF4J: Defaulting to no-operation (NOP) logger >> implementation >> >>> >> >> >> > SLF4J: See >> http://www.slf4j.org/codes.html#StaticLoggerBinderfor >> >>> >> >> >> > further details. >> >>> >> >> >> > 243 openjpa INFO [main] openjpa.Runtime - OpenJPA >> >>> dynamically >> >>> >> >> >> > loaded a validation provider. >> >>> >> >> >> > 596 openjpa INFO [main] openjpa.Runtime - Starting >> OpenJPA >> >>> >> 2.2.0 >> >>> >> >> >> > 630 openjpa INFO [main] openjpa.jdbc.JDBC - Using >> >>> dictionary >> >>> >> class >> >>> >> >> >> > "org.apache.openjpa.jdbc.sql.OracleDictionary". >> >>> >> >> >> > Exception in thread "main" > >>> nonfatal >> >>> >> >> >> > user error> >> org.apache.openjpa.persistence.ArgumentException: >> >>> >> Attempt >> >>> >> >> >> > to cast instance >> >>> "[persistdemo.ojpa.entities.RiskFactor@61578aab] >> >>> >> >> >> > [java.util.HashSet]" to PersistenceCapable failed. Ensur= e >> >>> that it >> >>> >> has >> >>> >> >> >> > been enhanced. >> >>> >> >> >> > >> >>> >> >> >> > Maybe because "java.util.HashSet" was loaded before the >> dynamic >> >>> >> >> >> > enhancer could get to it? >> >>> >> >> >> > >> >>> >> >> >> > Next, I tried performing build-time enhancement via Maven= , >> per >> >>> this >> >>> >> >> doc: >> >>> >> >> >> > http://openjpa.apache.org/enhancement-with-maven.html >> >>> >> >> >> > >> >>> >> >> >> > When I ran "mvn openjpa:enhance", it finished with succes= s, >> but >> >>> >> none >> >>> >> >> >> > of the classes in target/classes seemed to have be change= d >> >>> >> >> >> > (last-modified date same as compile-time). and re-runnin= g >> >>> results >> >>> >> in >> >>> >> >> >> > the same error and stack-trace. >> >>> >> >> >> > >> >>> >> >> >> > My openjpa:enhance configuration was: >> >>> >> >> >> > >> >>> >> >> >> > >> **/entities/*.class,java.util.HashSet >> >>> >> >> >> > true >> >>> >> >> >> > >> >>> >> true >> >>> >> >> >> > >> >>> >> >> >> > >> >>> >> >> >> > >> >>> >> >> >> > Next, I tried invoking with: >> >>> >> >> >> > >> >>> >> >> >> > -javaagent:/opt/apache-openjpa-2.2.0/openjpa-all-2.2.0.ja= r >> >>> >> >> >> > >> >>> >> >> >> > Same error - same stack trace. >> >>> >> >> >> > >> >>> >> >> >> > Then, I tried setting this property: >> >>> >> >> >> > openjpa.RuntimeUnenhancedClasses=3Dsupported >> >>> >> >> >> > >> >>> >> >> >> > Same error - same stack trace. >> >>> >> >> >> > >> >>> >> >> >> > >> >>> >> >> >> > Then, following a suggestion I found here: >> >>> >> >> >> > >> >>> >> >> >> >> >>> >> >> >> >>> >> >> >>> >> http://openjpa.208410.n2.nabble.com/JPA-adding-entities-to-EntityManager= Factory-programmatically-td210697.html >> >>> >> >> >> > >> >>> >> >> >> > I tried setting both: >> >>> >> >> >> > openjpa.RuntimeUnenhancedClasses=3Dsupported >> >>> >> >> >> > openjpa.MetaDataFactory=3Djpa(Types=3Djava.util.HashSet) >> >>> >> >> >> > >> >>> >> >> >> > BTW, this is a dead link >> >>> >> >> >> > "User's Guide on Enhancement" / >> >>> >> >> >> > >> >>> >> >> >> >> >>> >> >> >> >>> >> >> >>> >> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guid= e_pc_enhance >> >>> >> >> >> > (from page: >> http://openjpa.apache.org/entity-enhancement.html) >> >>> >> >> >> > >> >>> >> >> >> > So is there any way to use OpenJPA to persist objects >> related >> >>> via a >> >>> >> >> >> > link table? (there obviously must be, >> >>> >> >> >> > but it's a total mystery to me) I can't believe it's thi= s >> >>> >> difficult, >> >>> >> >> >> > I must be doing something really dumb. >> >>> >> >> >> > >> >>> >> >> >> > Regards, >> >>> >> >> >> > >> >>> >> >> >> > CW >> >>> >> >> >> >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > >> >>> >> >> > -- >> >>> >> >> > >> >>> ------------------------------------------------------------------- >> >>> >> >> > *SCJA. Jos=E9 Luis Cetina* >> >>> >> >> > >> >>> ------------------------------------------------------------------- >> >>> >> >> >> >>> >> >> >>> >> >> >> > > > > -- > *Rick Curtis*