Hi Gokhan, I'd been busy with work but kept this particular issue at the back of my mind for coming back to. How far did you get investigating it?
Firstly, I had no problem getting updateAttached (EntityManager em) to run fine on both SQL Server and Postgresql, got the count of 4. For updateDetached (EntityManager em), I was able to get it to 'work' by allowing cascading from C to B on the @ManyToOne
From the lack of response to this issue, I'm thinking this might be a design
decision the bigger picture of which is eluding me. Anyone would care to shed some light on this, why @ManyToOne(cascade= CascadeType.ALL) solves the problem reported? On MySQL, updateDetached works fine with the modification: @ManyToOne(cascade=CascadeType.ALL) But for updateAttached, the issue of apparently attempting to save instances of C before those of B persists with and without the above change: =================================================== [java] Caused by: <0.9.7-incubating fatal general error> org.apache.openjpa.persistence.PersistenceException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred. [java] at org.apache.openjpa.kernel.BrokerImpl.newFlushException( BrokerImpl.java:2118) [java] at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java :1965) [java] at org.apache.openjpa.kernel.BrokerImpl.flushSafe( BrokerImpl.java:1863) [java] at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion( BrokerImpl.java:1781) [java] at org.apache.openjpa.kernel.LocalManagedRuntime.commit( LocalManagedRuntime.java:80) [java] at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java :1311) [java] at org.apache.openjpa.kernel.DelegatingBroker.commit( DelegatingBroker.java:866) [java] at org.apache.openjpa.persistence.EntityManagerImpl.commit( EntityManagerImpl.java:409) [java] ... 23 more [java] Caused by: <0.9.7-incubating nonfatal general error> org.apache.openjpa.persistence.PersistenceException: Cannot add or update a child row: a foreign key constraint fails (`test/test_c`, CONSTRAINT `FK_TEST_C_REFERENCE_TEST_B` FOREIGN KEY (`B_ID`) REFERENCES `test_b` (`B_ID`)) {prepstmnt 7832149 INSERT INTO TEST_C (c_id, B_ID) VALUES (?, ?) [params=(int) 4, (int) 4]} [code=1452, state=23000] [java] FailedObject: [EMAIL PROTECTED] [java] at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException( DBDictionary.java:3782) [java] at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore( SQLExceptions.java:97) [java] at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore( SQLExceptions.java:67) [java] at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal( PreparedStatementManagerImpl.java:106) [java] at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush( PreparedStatementManagerImpl.java:71) [java] at org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flushPrimaryRow( OperationOrderUpdateManager.java:203) [java] at org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flush( OperationOrderUpdateManager.java:89) [java] at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush( AbstractUpdateManager.java:89) [java] at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush( AbstractUpdateManager.java:72) [java] at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush( JDBCStoreManager.java:514) [java] at org.apache.openjpa.kernel.DelegatingStoreManager.flush( DelegatingStoreManager.java:130) [java] ... 30 more [java] Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Cannot add or update a child row: a foreign key constraint fails (`test/test_c`, CONSTRAINT `FK_TEST_C_REFERENCE_TEST_B` FOREIGN KEY (`B_ID`) REFERENCES `test_b` (`B_ID`)) {prepstmnt 7832149 INSERT INTO TEST_C (c_id, B_ID) VALUES (?, ?) [params=(int) 4, (int) 4]} [code=1452, state=23000] [java] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap( LoggingConnectionDecorator.java:191) [java] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$800( LoggingConnectionDecorator.java:56) [java] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate (LoggingConnectionDecorator.java:857) [java] at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate( DelegatingPreparedStatement.java:269) [java] at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate (JDBCStoreManager.java:1363) [java] at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal( PreparedStatementManagerImpl.java:95) [java] ... 37 more =================================================== J-Philippe. On 5/4/07, Gokhan Ergul <[EMAIL PROTECTED]> wrote:
Philippe, I must admit I'm quite illiterate when it comes to Eclipse --ditched it a long time ago in favor of Idea. You must be right about the build.xml being a not-so-straightforward root for Eclipse import, it didn't occur to me that it could be used that way. Having said that, here's my (purely speculative) comments about the problem you're having: > [java] javax.persistence.PersistenceException: Invalid or inaccessible > provider class: org.apache.openjpa.persistence.PersistenceProviderImpl > [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute( > ExecuteJava.java:180) That sure looks like a classpath problem to me, and the fact that it's coming from ant..ExecuteJava is somewhat telling, the Eclipse-generated build.xml is running a <java ..> task instead of an <openjpac> task, possibly with a different classpath. > Is the use of <taskdef name="openjpac" classname=" > org.apache.openjpa.ant.PCEnhancerTask"/> > the equivalent of what is done for the examples with > > <!-- > Specifying the openjpa jar as the javaagent argument is > necessary in order for automatic class-enhancement to > work. > --> > <jvmarg value="-javaagent:${javaagent}"/> ? <openjpac> task performs a build-time class enhancement, whereas the "-javaagent" method performs a run-time enhancement, you can use either as long as the environment is setup properly. Since the above exception is coming from a <java> task, I'm assuming you're using run-time enhancement method, then it boils down to setting the correct classpath entries. If you can post the relevant parts of your build.xml, it'll be easier to spot the problem. Gokhan.