José, Thanks - I sent the two entities to John (this list). The pom.xml is attached...
-Chris On Mon, Nov 19, 2012 at 9:54 AM, José Luis Cetina <maxtorz...@gmail.com> wrote: > Please send your 2 entities and your pom configuration whit the enhance > plugin. > El 19/11/2012 08:46, "Chris Wolf" <cwolf.a...@gmail.com> escribió: > >> José, >> >> I tried List/ArrayList - same error. Thanks.... >> >> -Chris >> >> On Sun, Nov 18, 2012 at 9:47 PM, José Luis Cetina <maxtorz...@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" <cwolf.a...@gmail.com> escribió: >> > >> >> José, >> >> >> >> Thanks for your reply. My pom.xml setup is very similar to yours and >> >> the "enhance" goal runs without error, but, as I mentioned, >> >> I still get the error on "casting java.util.HashSet". Are you 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(AbstractEntityManagerImpl.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 instant 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é Luis Cetina <maxtorz...@gmail.com >> > >> >> wrote: >> >> > I have this in my pom.xml for ENHANCMENT and works: >> >> > >> >> > <!--OPENJPA ENHANCMENT--> >> >> > <plugin> >> >> > <groupId>org.apache.openjpa</groupId> >> >> > <artifactId>openjpa-maven-plugin</artifactId> >> >> > <version>2.2.0</version> >> >> > <configuration> >> >> > <includes>mypackage/model/*.class</includes> >> >> > >> <addDefaultConstructor>true</addDefaultConstructor> >> >> > >> >> > <enforcePropertyRestrictions>true</enforcePropertyRestrictions> >> >> > >> >> > <connectionDriverName>com.mysql.jdbc.Driver</connectionDriverName> >> >> > <connectionProperties> >> >> > driverClass=${database.driver.name}, >> >> > jdbcUrl=${database.connection.url}, >> >> > user=${database.user}, >> >> > password=${database.password}, >> >> > minPoolSize=5, >> >> > acquireRetryAttempts=3, >> >> > maxPoolSize=20 >> >> > </connectionProperties> >> >> > </configuration> >> >> > <executions> >> >> > <execution> >> >> > <id>enhancer</id> >> >> > <phase>process-classes</phase> >> >> > <goals> >> >> > <goal>enhance</goal> >> >> > </goals> >> >> > </execution> >> >> > </executions> >> >> > <dependencies> >> >> > <dependency> >> >> > <groupId>org.apache.openjpa</groupId> >> >> > <artifactId>openjpa</artifactId> >> >> > <version>2.2.0</version> >> >> > </dependency> >> >> > </dependencies> >> >> > </plugin> >> >> > >> >> > In my persistence.xml i have: >> >> > >> >> > <property name="openjpa.ConnectionUserName" >> value="${db.username}"/> >> >> > <property name="openjpa.ConnectionPassword" >> >> value="${db.password}"/> >> >> > <property name="openjpa.ConnectionURL" value="${db.url}"/> >> >> > <property name="openjpa.ConnectionDriverName" >> >> > value="${db.driver.class}"/> >> >> > >> >> > You can replace the database properties in persistence.xml with 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 <cwolf.a...@gmail.com> >> >> > >> >> >> I wrote a shell script to directly invoke PCEnhancer on class >> >> >> 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.class (The >> >> >> filename, directory name, or volume label syntax is incorrect) >> >> >> at >> >> >> >> >> >> org.apache.openjpa.lib.conf.Configurations.launchRunnable(Configurations.java:744) >> >> >> >> >> >> On Sun, Nov 18, 2012 at 10:37 AM, Chris Wolf <cwolf.a...@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" or >> >> >> > "EclipseLink"). Of course, I have OpenJPA configured >> >> >> > as my JPA provider, I am in a plain Java SE environment with >> >> >> > 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="marketData") >> >> >> > public Set<RiskFactor> getRiskFactors() { >> >> >> > return this.riskFactors; >> >> >> > } >> >> >> > >> >> >> > Second M2M entity "RiskFactor": >> >> >> > >> >> >> > //bi-directional many-to-many association to MarketData >> >> >> > @ManyToMany >> >> >> > @JoinTable( >> >> >> > name="MARKET_DATA__RISK_FACTOR" >> >> >> > , joinColumns={ >> >> >> > @JoinColumn(name="RISK_FACTOR_ID", >> >> >> nullable=false) >> >> >> > } >> >> >> > , inverseJoinColumns={ >> >> >> > @JoinColumn(name="MARKET_DATA_ID", >> >> >> nullable=false) >> >> >> > } >> >> >> > ) >> >> >> > public Set<MarketData> 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#StaticLoggerBinder for >> >> >> > 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" <openjpa-2.2.0-r422266:1244990 nonfatal >> >> >> > user error> org.apache.openjpa.persistence.ArgumentException: >> Attempt >> >> >> > to cast instance "[persistdemo.ojpa.entities.RiskFactor@61578aab] >> >> >> > [java.util.HashSet]" to PersistenceCapable failed. Ensure 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 success, but >> none >> >> >> > of the classes in target/classes seemed to have be changed >> >> >> > (last-modified date same as compile-time). and re-running results >> in >> >> >> > the same error and stack-trace. >> >> >> > >> >> >> > My openjpa:enhance configuration was: >> >> >> > <configuration> >> >> >> > <includes>**/entities/*.class,java.util.HashSet</includes> >> >> >> > <addDefaultConstructor>true</addDefaultConstructor> >> >> >> > >> <enforcePropertyRestrictions>true</enforcePropertyRestrictions> >> >> >> > </configuration> >> >> >> > >> >> >> > >> >> >> > Next, I tried invoking with: >> >> >> > >> >> >> > -javaagent:/opt/apache-openjpa-2.2.0/openjpa-all-2.2.0.jar >> >> >> > >> >> >> > Same error - same stack trace. >> >> >> > >> >> >> > Then, I tried setting this property: >> >> >> > openjpa.RuntimeUnenhancedClasses=supported >> >> >> > >> >> >> > Same error - same stack trace. >> >> >> > >> >> >> > >> >> >> > Then, following a suggestion I found here: >> >> >> > >> >> >> >> >> >> http://openjpa.208410.n2.nabble.com/JPA-adding-entities-to-EntityManagerFactory-programmatically-td210697.html >> >> >> > >> >> >> > I tried setting both: >> >> >> > openjpa.RuntimeUnenhancedClasses=supported >> >> >> > openjpa.MetaDataFactory=jpa(Types=java.util.HashSet) >> >> >> > >> >> >> > BTW, this is a dead link >> >> >> > "User's Guide on Enhancement" / >> >> >> > >> >> >> >> >> >> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_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 this >> difficult, >> >> >> > I must be doing something really dumb. >> >> >> > >> >> >> > Regards, >> >> >> > >> >> >> > CW >> >> >> >> >> > >> >> > >> >> > >> >> > -- >> >> > ------------------------------------------------------------------- >> >> > *SCJA. José Luis Cetina* >> >> > ------------------------------------------------------------------- >> >> >>
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>ms.algo.adapt.poc.persist</groupId> <artifactId>jpademo-2</artifactId> <version>1.0-SNAPSHOT</version> <!--packaging>pom</packaging--> <organization> <name>IBM Algo Risk Services</name> <url>https://w3-connections.ibm.com/communities/service/html/communityview?communityUuid=c87d65f4-b8cf-46fb-a860-d08e4c59ebf1</url> </organization> <issueManagement> <system>SFDC</system> <url>http://www.salesforce.com</url> </issueManagement> <!--modules> <module>adapt-lib</module> <module>adapt-camel</module> </modules--> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <hornet.version>2.2.5.Final</hornet.version> <org.springframework.version>3.1.0.RELEASE</org.springframework.version> <hibernate.version>3.5.6-Final</hibernate.version> <openjpa.version>2.2.0</openjpa.version> <!--scala.version>2.9.2</scala.version--> </properties> <repositories> <repository> <id>jboss-public-repository-group</id> <name>JBoss Public Repository Group</name> <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url> <layout>default</layout> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> </snapshots> </repository> <repository> <id>central.maven.org</id> <name>central.maven.org</name> <url>http://central.maven.org/maven2/</url> <layout>default</layout> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> </snapshots> </repository> <repository> <id>mvn3rdparty</id> <url>file:///opt/mvn3rdparty/repo</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>jboss-public-repository-group</id> <name>JBoss Public Repository Group</name> <url>http://repository.jboss.org/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>apache.snapshots</id> <name>JBoss Snapshots Group</name> <url>https://repository.apache.org/content/groups/snapshots-group/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.5.8</version> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6_g</artifactId> <version>11.2</version> </dependency> <dependency> <groupId>org.apache.openjpa</groupId> <artifactId>openjpa</artifactId> <version>${openjpa.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.openjpa</groupId> <artifactId>openjpa-maven-plugin</artifactId> <version>2.2.0</version> <configuration> <includes>**/entities/*.class,java.util.ArrayList.class</includes> <excludes>**/entities/XML*.class</excludes> <addDefaultConstructor>true</addDefaultConstructor> <enforcePropertyRestrictions>true</enforcePropertyRestrictions> </configuration> <executions> <execution> <id>enhancer</id> <phase>process-classes</phase> <goals> <goal>enhance</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.apache.openjpa</groupId> <artifactId>openjpa</artifactId> <version>${openjpa.version}</version> </dependency> </dependencies> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.1</version> <configuration> <locales>en</locales> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pdf-plugin</artifactId> <!--version>1.1</version--> <version>1.2-SNAPSHOT</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.8.1</version> <configuration> <!--detectLinks>true</detectLinks> <detectOfflineLinks>true</detectOfflineLinks--> <links> <link>http://docs.jboss.org/hornetq/2.2.5.Final/api</link> <!-- follwing is wrong version, but JBoss doesn't publish current org.hornetq.jms --> <link>http://hornetq.sourceforge.net/docs/hornetq-2.0.0.CR2/api</link> <link>http://docs.oracle.com/javaee/6/api</link> <link>http://static.springsource.org/spring/docs/3.1.x/javadoc-api</link> <link>http://camel.apache.org/maven/current/camel-core/apidocs</link> <link>http://camel.apache.org/maven/current/camel-spring/apidocs</link> <link>http://camel.apache.org/maven/current/camel-jms/apidocs</link> <link>http://camel.apache.org/maven/current/camel-ftp/apidocs</link> <link>http://camel.apache.org/maven/current/camel-quartz/apidocs</link> <link>http://camel.apache.org/maven/current/camel-script/apidocs</link> <link>http://camel.apache.org/maven/current/camel-velocity/apidocs</link> </links> </configuration> </plugin> </plugins> <resources> <resource> <directory>src/main/resources/openjpa</directory> <excludes> <exclude>.svn</exclude> <exclude>**/.svn/*</exclude> </excludes> <includes> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> </resources> <testResources> <testResource> <directory>src/test/resources</directory> <excludes> <exclude>.svn</exclude> <exclude>**/.svn/*</exclude> </excludes> <includes> <include>**/*</include> </includes> </testResource> </testResources> </build> <reporting> <excludeDefaults>true</excludeDefaults> <outputDirectory>${project.build.directory}/site</outputDirectory> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.4</version> <configuration> <dependencyDetailsEnabled>true</dependencyDetailsEnabled> <dependencyLocationsEnabled>true</dependencyLocationsEnabled> </configuration> <reportSets> <reportSet> <reports> <report>dependencies</report> <report>scm</report> </reports> </reportSet> </reportSets> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.8</version> </plugin> </plugins> </reporting> </project>