How to specifiy Cascase None for OneToMany
Hi, My application is an EJb3.0 running on WL10.3 My requirement is that in OneToMany Relationship , if the One Entity is deleted , Many Entity should not be deleted and should be set to null . When I try to delete One , I get integrity constraint violation exception. I used to get the same behaviour with ManyToMany relations and I had the same requirement i.e do not delete the other association end. I solved that problem by not specifying any cascade which is equivalent to CascadeType = None . @ManyToMany(targetEntity=Image.class ,fetch=FetchType.LAZY) But this trick is not working for @OneToMany. How to do i tell Open JPA that do not delete the association end, Just set the child records to null and delete this entity ? This is my code for OneToMany (Campaign to CampaignTarget @OneToMany(targetEntity=CampaignTarget.class, mappedBy = campaign, fetch=FetchType.LAZY) @ManyToOne(targetEntity=Campaign.class, fetch = FetchType.LAZY) One of the solution provided on Google is to If we try to delete a parent record without deleting the child records, we must set the foreign-key field for all children to NULL before removing the parent. Why should I do this extra set null when I have set cascade to none ? It worked with manytomany .. Is this the only appropiate solution available to handle such problem ? Thanks ! -- View this message in context: http://n2.nabble.com/How-to-specifiy-Cascase-None-for-OneToMany-tp4426059p4426059.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
RE: Open JPA generates incorrect Union All for Date and Boolean Datatype
Well thanks for your opinion .. Id is the primary key which is a String not Long or int (Obviously with millions of records , i wouldnt want to have primary key within boundary of long or int ) and all tables of my application has the same kind of id column ...Isnt it better and more clear than having long for one , int for another and string for rest ? So far I havent come across any such application .. What is the case when we would want such a scenerio ? But I still donot get the idea that Entity should not be part of inheritance hierarchy ! Infact with 3.0 specification , entity should behave like any other object model and support all kind of OOPS fundamentals ! Such cases include many-to-many linking tables and subordinate tables with a foreign key reference back to their parent table. With my limited knowledge of associations .. I didnt get the issue clearly here .. What will be the issue with mapping table/ref column since all primary keys are of same kind .. ? What could go wrong ghastly ..? Could you elaborte here ? -- View this message in context: http://n2.nabble.com/Open-JPA-generates-incorrect-Union-All-for-Date-and-Boolean-Datatype-tp4093559p4426171.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
OpenJPA 1.2.1, Oracle Stored Procedures and OUT parameters
I've been trying to determine how to call an Oracle 11g stored object that returns a REF CURSOR. So far, I've tried to create a stored function the returns a SYS_REFCURSOR and also a stored procedure that uses an OUT parameter of type SYS_REFCURSOR. Regardless how I attempt to perform this action to obtain a result set, I cannot seem to obtain the usable result set within my application. For instance: //SQL CREATE OR REPLACE PROCEDURE P_RETRIEVE_SET( RESULTS OUT SYS_REFCURSOR ) IS BEGIN OPEN RESULTS FOR SELECT * FROM MY_TABLE; END ; //Java EntityManager em = MyEntityFactory.createEntityManager(MY_PERSISTANCE_UNIT); Query qry = em.createNativeQuery(P_RETRIEVE_SET(?)); List resultList = qry.getSingleResult(); for (Object o : resultList) { System.out.println(o); } I've tried this same type of logic using the following: 1) NamedNativeQueries 2) Stored Function that returns SYS_REFCURSOR 3) CALL P_RETRIEVE_SET(?) The best I ever got was a return Vector from the Query that contained a single element of type OracleResultSetImpl. However, this result set was close and unusable for iteration or meta-data retrieval. I've looked for several hours online to find an example of this functionality with no avail. Any assistance would be appreciated. I have found a similar issue in OPENJPA-918, but this only applied to 2.0.0M2, not 1x. https://issues.apache.org/jira/browse/OPENJPA-918?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel Thank you, Seth - Seth Jackson -- View this message in context: http://n2.nabble.com/OpenJPA-1-2-1-Oracle-Stored-Procedures-and-OUT-parameters-tp4428715p4428715.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Re: Confused about why Im getting this error
Thomas, When you run your application in JSE, that is, outside an application server, you usually should configure the persistence.xml to use entity manager transactions instead of JTA. Please change transaction-type attribute like below and see whether anything changed: persistence-unit name=ExampleJPA transaction-type=RESOURCE_LOCAL Cheers, Milosz persistence.xml ?xml version=1.0 encoding=UTF-8? persistence version=1.0 xmlns=http://java.sun.com/xml/ns/persistence; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd; persistence-unit name=ExampleJPA transaction-type=JTA providerorg.apache.openjpa.persistence.PersistenceProviderImpl/provider classcom.trukoda.examples.jpa.Account/class classcom.trukoda.examples.jpa.Host/class properties !-- property name=openjpa.ConnectionDriverName value=org.hsqldb.jdbcDriver/ property name=openjpa.ConnectionURL value=jdbc:hsqldb:file:/tmp/JPA-Test / property name=openjpa.ConnectionUserName value=sa / property name=openjpa.ConnectionPassword value= / property name=openjpa.Log value=DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE Runtime=INFO, Tool=INFO, SQL=TRACE/ -- property name=openjpa.ConnectionURL value=jdbc:derby:build/openjpa-database;create=true/ property name=openjpa.ConnectionDriverName value=org.apache.derby.jdbc.EmbeddedDriver/ property name=openjpa.ConnectionUserName value=user/ property name=openjpa.ConnectionPassword value=secret/ /properties /persistence-unit /persistence Thanks for looking at this. Thomas On Jan 19, 2010, at 4:54 PM, Miłosz Tylenda wrote: Thomas, Can you check or post your persistence.xml? Maybe you configured your ExampleJPA persistence unit to use JTA transactions instead of entity manager (RESOURCE_LOCAL) transactions. Greetings, Milosz I am not running this from an IDE. Command line using ant for compiles and enhancement but not to run the main doing that by hand Thanks for looking at my issue Thomas Sent from my iPhone On Jan 19, 2010, at 5:20, Jean-Baptiste BRIAUD -- Novlog j-b.bri...@novlog.com wrote: Maybe a classpath issue in the IDE project's config ? On Jan 18, 2010, at 02:15 , Thomas Polliard wrote: Doing an example trying to learn OpenJPA and JPA I ran into a strange problem. java.lang.ClassNotFoundException: com.arjuna.jta.JTA_TransactionManager java.lang.ClassNotFoundException: com.bluestone.jta.SaTransactionManagerFactory java.lang.ClassNotFoundException: org.openejb.OpenEJB java.lang.ClassNotFoundException: com.sun.jts.jta.TransactionManagerImpl java.lang.ClassNotFoundException: com.inprise.visitransact.jta.TransactionManagerImpl I am not using Any of these yet for some reason, I am getting this error The problem is Only when I run the main program: Main.java package com.trukoda.examples.jpa; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; public class Main { public static void main(String[] args) { EntityManagerFactory factory = Persistence.createEntityManagerFactory(ExampleJPA); Account user1 = new Account(polliard); Account user2 = new Account(mcclung); Host host1 = new Host(uranium); Host host2 = new Host(thorium); EntityManager em = factory.createEntityManager(); em.getTransaction().begin(); em.persist(host1); em.persist(host2); em.getTransaction().commit(); } } Any idea why this this would causes classes I am not referencing from being loaded. I am including the following in my classpath: .:/Users/polliard/Library/Java/Derby/10.5.3.0/derby.jar:/Users/ polliard/Library/Java/Openjpa/2.0-M3/openjpa-all-2.0.0-M3.jar The two accounts (Account and Host) are basic Entities and the database gets created without issue using the mappingtool. Thanks for any assistance, Thomas
Re: superclass mapping.
I think what you need is equivalent of @MappedSuperclass annotation in XML ..which I dont know.. :( If you can , annoate Cat like below , it would work. @MappedSuperclass public class Cat { Hope this will narrow down your search - H -- View this message in context: http://n2.nabble.com/superclass-mapping-tp4416205p4431862.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: How to specifiy Cascase None for OneToMany
Nope .. it didnt work. Does this need some property in persistence.xml also ? My new entity looks like this now CampaignTarger.class @ManyToOne(targetEntity=Campaign.class, fetch = FetchType.LAZY ) @JoinColumn(name = campaign_Ref ,nullable=true) @ForeignKey(deleteAction=ForeignKeyAction.NULL) private Campaign campaign ; Campaign.class @OneToMany(targetEntity=CampaignTarget.class, mappedBy = campaign, fetch=FetchType.LAZY ) private CollectionCampaignTarget campaignTargets; This is the complete stacktrace Caused by: java.lang.Exception: openjpa-1.1.0-r422266:657916 nonfatal store error org.apache.openjpa.util.StoreException: [BEA][Oracle JDBC Driver][Oracle]ORA-02292: integrity constraint (XXX.FK_CAMPAIGNTARGET_CAMPAIGN) violated - child record found {prepstmnt 1705 DELETE FROM Campaign_T WHERE ID = ? AND version = ? [params=(String) 1002, (int) 1]} [code=2292, state=HY000] FailedObject: com.tieto.tix.imaging.domain.Campaign-1002 at org.apache.openjpa.util.Exceptions.replaceNestedThrowables(Exceptions.java:249) at org.apache.openjpa.util.OpenJPAException.writeObject(OpenJPAException.java:192) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461) Persistence Unit looks like this in xml persistence-unit name=imagingDS transaction-type=JTA jta-data-sourceimagingDS/jta-data-source properties property name=openjpa.jdbc.DBDictionary value=oracle(UseGetBytesForBlobs=true,maxEmbeddedBlobSize=-1,maxEmbeddedClobSize=-1)/ property name=openjpa.jdbc.SubclassFetchMode value=none/ /properties /persistence-unit -- View this message in context: http://n2.nabble.com/How-to-specifiy-Cascase-None-for-OneToMany-tp4426059p4431913.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: How to specifiy Cascase None for OneToMany
Hi, Hmm... It worked for me on a standalone openJPA testcase against derby DB. As you are running on WLS and against oracle DB, I created a testcase with similar environment. http://n2.nabble.com/file/n4432179/EJBTestCase.zip EJBTestCase.zip Please download the attached zip file. Modify build.xml, build-properties.xml and META-INF\persistence.xml to reflect your local environment. Then run ant ( this will create db tables , build EJB and deploy it on WLS) ant test.remote ( this will run the EJB which will remove the primary row and insert new entitys) After running the above testcase, I can clearly see that the foreignkey column is nullified when I remove the primay row ( using em.remove()) Regards, Ravi. -- View this message in context: http://n2.nabble.com/How-to-specifiy-Cascase-None-for-OneToMany-tp4426059p4432179.html Sent from the OpenJPA Users mailing list archive at Nabble.com.