Cascade delete in many to many association

Hi All,
    I have a usecase, there is an association with many to many cardinality  between 3 EO's. If i delete  any record in master, the corresponding childs all should delete.
    So appreciate if any alternatives on above usecase. Thanks in advance

Hi,
cascade delete is a function of the database. When you enable cascade delete for an entity operation then this only produces the proper SQL code for deleting a data object. If you have a many-to-many relation then this means you have multiple master and child records, which I think makes your "If i delete  any record in master, the corresponding childs all should delete" impossible.
for what its worth, please read
Creating a Business Domain Layer Using Entity Objects - 11g Release 2 (11.1.2.3.0)
to learn how to parse and delete detail records  from an entity object
http://docs.oracle.com/cd/E35521_01/web.111230/e16182/bcentities.htm#CEGJAFCF
The last document is about posting orders (e.g. create a master record before you create detail records). However, with a few changes you can reverse this to perform a delete operation (just add this code to the entity impl classes of the entities so they delete their child objects
Frank

Similar Messages

  • Delete entity that participate in many to many association

    Hi all,
    I have two tables related by a many to many relationship (for ex department and employee).
    So I have three tables:
    Department: table of departments
    Employee: table employees
    deptEmp: the association table relating the employees to the departments.
    When a department is deleted, all the corresponding rows in deptEmp table should also be deleted (and same for employee).
    On the entity level, I have created the many to many association (between department and employee) and a one to many association for each of department and employee entities to deptEmp entity (deptEmptAssoc from department to deptEmp and empDeptAssoc employee  to deptEmp).
    I configured the deptEmptAssoc association to be a composition and implement the cascading delete, and it is working fine. When I delete a department, the corresponding rows in deptEmp are deleted.
    The problem is that when I try to do the same for empDeptAssoc, JDev gives me a warning and doesn’t apply the composition neither the cascading delete.
    I tried to override the remove method of employee entity to also remove the corresponding deptEmp but it also didn’t work.
    So any hint or pointer how to achieve this? How to have a many to many association and be able to delete both sides of the association?
    Thank you.

    Hi,
    This behavior can be done by overriding the postChanges method as follow:
      public void postChanges(TransactionEvent transactionEvent) {
            if(getPostState() == STATUS_DELETED){
                RowIterator mmIterator = getMM();
                while (mmIterator.hasNext()){
                    EntityImpl row = (EntityImpl)mmIterator.next();
                    row.remove();
    row.postChanges(transactionEvent);
            super.postChanges(transactionEvent);
    N.B.1  In the xml file of the viewLink, the composition association (and implement cascade delete) should not be checked.
    N.B.2  with these flags unchecked, ADF will not control the posting of entities in case the department and the deptEmp entities were both newly created. To fix the issue, the deptEmp entity should also override the postChanges method as follow:
                        public void postChanges(TransactionEvent transactionEvent) {
            if (getPostState() == STATUS_NEW ||
                  getPostState() == STATUS_MODIFIED) {
                EntityImpl dept = getDept();
                if (dept != null) {
                  if (dept.getPostState() == STATUS_NEW) {
    dept.postChanges(transactionEvent);
                                                    // do the same for the Employee entity if needed
            super.postChanges(transactionEvent);
    Regards.

  • Adding/removing many-to-many associations with intersection tables

    Hello,
    I am using Jdeveloper 11g with ADFBC.
    I have some many to many associations in my application. For example User and Category are associated and there is an intersection entity (UserCategory - Columns are UserId, CategoryId) to save these associations.
    What is the correct method for adding or removing categories assigned to user?
    Thanks.
    Edited by: Deniz Gulmez on 01-Nov-2009 03:25

    I found an example for Jdeveloper 10g, which is discussed [ADF] Adding/deleting entries in a many-to-many relationship
    In that example, many-to-many association is defined as two 1-to-many associations. Actually i've been searching since last week for an example which is made with many-to-many associations but no help. I will change my Model structure if it is not an efficient way to define many-to-many associations with intersection tables.
    I wonder if it is possible to write some methods like :
    addCategoryToUser(String userId, String categoryId)
    removeCategoryToUser(String userId, String categoryId)
    addCategories(String userId, List categoryIds)
    vs.
    Of course i am able to do these by creating a new Row in UserCategoryView (Intersection view), setting it's attributes and saving. Or the opposite, finding the row in intersection table and deleting it.
    For example:
    public void removeCategoryFromUser(String userId, String categoryId){
    ViewObjectImpl vo = this.getUserCategories1();
    vo.setWhereClause("USER_ID = :userId AND CATEGORY_ID = :categoryId");
    vo.defineNamedWhereClauseParam("userId", null, null);
    vo.defineNamedWhereClauseParam("categoryId", null, null);
    vo.setNamedWhereClauseParam("userId", userId);
    vo.setNamedWhereClauseParam("categoryId", categoryId);
    vo.executeQuery();
    Row row = vo.first();
    row.remove();
    I wonder if there is a more efficient way. Any samples would be appreciated.
    Edited by: Deniz Gulmez on 01-Nov-2009 05:49

  • [ADF] Adding/deleting entries in a many-to-many relationship

    I am using JDeveloper 10.1.3 and the ADF BC / ADF Model / ADF Faces / JSF technology stack.
    For this question, I am using the SRDemo application as an example, specifically the many-to-many relationship between USERS and PRODUCTS (the Staff Expertise relationship), outlined in red in this schema diagram: Image Link
    Users may have any number of product expertise areas and many users may have the same product expertise area. For the purposes of this example I have added two reference fields from the PRODUCT table into the ExpertiseAreas VO (Name and Description), outlined in red in this data control palette section: Image Link
    I have created a page which shows the details of a user (1), along with a table showing the expertise areas the user has (3), and a table of all the products available (2), numbered on this design page: Image Link and corresponding to the numbered data controls on this data control palette section: Image Link, where 1 is rendered as an ADF Read-only Form, 2 is an ADF Read-only Table with a tableSelectMany element in the selection facet, and 3 is also an ADF Read-only Table.
    What I am trying to do is have the tableSelectMany element reflect which of the products are linked to the current user in the expertise areas relationship (by having the checkbox for currently linked products checked), and when you check or uncheck a product's checkbox, it should add or remove the row in the EXPERTISE_AREAS intersection table, respectively (asume for this example that there are default values for Expertise Level and Notes).
    So far I have been following the process used in section 19.8 of the ADF Developer's Guide for Forms/4GL Developers, which describes how to set up a selectManyShuttle which implements the adding and deleting functionality. So I have a Client Interface method in the Application Module, updateSkillsForCurrentStaff (described in section 10.6.7.2), and I have a selection listener for the assignment table in the backing bean for the page, which calls the updateSkillsForCurrentStaff method:
    public void selectionChanged(SelectionEvent event)
      BindingContainer bc = getBindings();
      DCIteratorBinding productsIB = (DCIteratorBinding)bc.get("ProductListIterator");
      Set keys = getTable1().getSelectionState().getKeySet();
      Iterator iter = keys.iterator();
      List productIds = new Vector();
      while (iter.hasNext())
        String product = ((Key)iter.next()).toStringFormat(true);
        productsIB.setCurrentRowWithKey(product);
        ViewRowImpl productRow = (ViewRowImpl)productsIB.getCurrentRow();
        Number productId = (Number)productRow.getAttribute("Id");
        productIds.add(productId);
      OperationBinding ob = bc.getOperationBinding("updateSkillsForCurrentStaff");
      Map pm = ob.getParamsMap();
      pm.put("productIds", productIds);
      ob.execute();
    All of this works, but I can't work out how to link the selection state of the assignment table to the expertise areas that are linked to the user. Also I think the method listing above must be a bit of a hack, but I don't know enough about this to know if there's an easier way of doing it.
    Any help is appreciated.

    Have a look at this example I cooked up for you.
    http://radio.weblogs.com/0118231/2006/10/03.html#a739
    It might not be the first way one thinks to implement something, but it illustrates a very interesting, model-centric approach to the problem you propose.
    My feelings won't be hurt if you prefer a more view-centric approach, but I wanted to illustrate what was a maximally-model-centric solution (in fact, which doesn't even require a backing bean!) If you like a more view-centric approach, I can help you figure out what's wrong with your key-handling above. For one, I would probably start by passing the Set of Key's directly to the middle tier application module method to eliminate client-side code.
    Check it out and let me know what you think. Try it directly in the Business Components Tester to appreciate one of the benefits a model-centric solution can bring.

  • Problem in Many-to-Many Associations (JBO-27014 error)

    I am facing a problem during insertion in an Intersection table.
    I have 3 tables Customer, Accounts and Customer_Account. In order to implement the Many to Many relationship between Customer and Accounts, I created an intersection table Customer_Account.
    Table Structure
    CUSTOMER
    Cust_id NUMBER NOT NULL PK
    Name VARCHAR2(50) NOT NULL
    ACCOUNT
    Account_Id NUMBER NOT NULL PK,
    Account_number NOT NULL,
    Sort_Code NUMBER NOT NULL,
    Account_Type VARCHAR2(10) NOT NULL
    CUSTOMER_ACCOUNT
    Cust_Id NUMBER NOT NULL,
    Account_Id NUMBER NOT NULL
    I created an Association CustAcctAsso between Customer and Account with Customer_Account as intersection entity. Then created a viewlink CustAcctViewLink with CustomerView as Source entity, AccountView as Destination entity and selected the CustAcctAsso as association.
    I included this in the application module using the following steps
    Selected AccountView via CustAcctViewLink in the Available view pane and selected CustomerView in Data model pane. Clicked > to add AccountView via CustAcctViewLink as a restricted view.
    Also added CustomerView via CustAcctViewLink as a restricted view.
    When I tried to insert data through the second restricted view I am getting an JBO 27014 Attribute Sort Code in Account is required.
    It would be very helpful if someone gives me a solution quickly.
    Thanks
    Renuka

    Thanks, now I am able to insert data into CUSTOMER and ACCOUNT table, but not in the intersection table.
    It seems that we cannot do any insertion into the intersection table. Please advice me, this is urgent.OK here's what you need to do to insert a new row in both ACCOUNT and INTERSECTION tables.
    1. Create a new viewobject with a join of INTERSECTION and ACCOUNT tables such that both are updateable but ACCOUNT is reference entity.
    -- This is assuming you want to insert a new account when you insert a new account id in the intersection table otherwise, you can make ACCOUNT entity readonly as well.
    2. Create a viewlink between Customer viewobject and this NewViewObject (1-* ViewLink).
    3. If the assumption in step 1 is NOT to update/insert new Accounts form this VO, then you're done. Add the new viewobject usage in your application module and you should be able to use it to edit/insert intersection details.
    Otherwise -
    Set the Updateable flag on AccountID (from the Account entity usage in the NewViewObject) to "never" udpateable.
    Set the Updateable flag on Other attributes from the Account entity usage in the NewViewObject to udpateable-while-new or always as desired.
    4. Select to generate EntityDefImpl subclass for Account table and override the protected method createInstance as below:
      protected EntityImpl createInstance(DBTransaction txn, AttributeList al)
        // TODO:  Override this oracle.jbo.server.EntityDefImpl method
        return super.createInstance(txn, al);
      }5. Select to generate a ViewRowImpl subclass with accessors for this NewViewObject
    6. Add the following logic in setAccountID() method (assuming AccountId attribute is editable and from Intersection entity)
    (Note you'll also have anothe attribute AccountId1 from Account entity which should be readonly as marked in step 3.)
    //get the current intersection entity.
    IntersectionImpl intersection = (IntersectionImpl)getEntity(1);
    setAttributeInternal(ACCOUNTID1, value);
    //if it is same as I added and is not the same as new one
    //framework may assign a new intersection entity based on FK.
    IntersectionImpl newIntersection = (IntersectionImpl)getEntity(1);
    IntersectionDefImpl intersectiondef = (IntersectionDefImpl)IntersectionImpl.getDefinitionObject();
    IntersectionEnrollmentImpl myVO = ((IntersectionEnrollmentImpl)getViewObject());
    DBTransaction dbtxn = myVO.getDBTransaction();
    //see if a intersection exists with this FK
    intersection = (IntersectionImpl)intersectiondef.findByPrimaryKey(dbtxn, IntersectionImpl.createPrimaryKey(value));
    //if this viewrow created a new intersection earlier which is different from
    //the current intersection entity, remove the old one as I created it.
    if ((intersectionAdded != null) && (intersection != intersectionAdded || newIntersection != intersectionAdded))
      if (intersection == null)
        //if I added this intersection as new, reuse-it.
        intersection = intersectionAdded;
        intersection.setIntersectionid(value);
      else
        //if I added this intersection as new, remove it.
        System.out.println(">>>>removing :"+intersectionAdded.getAttribute(0));
        intersectionAdded.remove();
        intersectionAdded = null;
    if (intersection == null)
      //if new intersection is null = no intersection exists with this key, then create a new one.
      intersection = (IntersectionImpl)intersectiondef.createInstance(dbtxn, new AttributeListImpl());
      intersection.setIntersectionid(value);
      intersectionAdded = intersection;
      setEntity(1, intersection);
      myVO.notifyRowUpdated(findRowSetForRow(this), new ViewRowImpl[]{this}, new int[]{2,3});
    else if (intersection != newIntersection)
      //otherwise, create a set the new intersection entity as my intersection entity reference
      setEntity(1, intersection);
      myVO.notifyRowUpdated(findRowSetForRow(this), new ViewRowImpl[]{this}, new int[]{2,3});
    }Now when you insert a new row in this NewViewObject, you can either enter a new Account or refer to an existing Account.
    The setAccountId() method will automatically bring the Account details for existing accounts or create a new Account entity as in the above logic.

  • HT201274 hi, I want to sell my iphone, how can I delete all contents? many thanks

    hi, I want to sell my iphone, how can I delete all contents? many thanks

    Settings > Messages > iMessage > Off
    Settings > FaceTime > Off
    Settings > iCloud > Delete Account
    Settings > General > Reset > Erase All Content and Settings

  • Many-to-many association: inserting in the detail table fails

    I'm using jdeveloper 11g and configured the many-to-many association as described in the documentation, so I have accessors in both directions, with composition association and a many-to-many link view. Using the business component browser, the link view works for viewing the data in both directions, as one would expect, however inserting in the detail table fails as follows: the key of the master table is the new value of the detail table's key column instead of the intersection table's foreign key column. Is this a known problem, or is there something I have done wrong?

    If your m-m join table has additional fields there best solution is normally to define a class for the join table.
    i.e.
    beforeProgram
    -m-m-> Assumption
    Assumption
    -m-m-> Program (optional/read-only)
    -> after
    Program
    -1-m-> ProgramAssumptionAssociation (private-owned)
    ProgramAssumptionAssociation
    -1-1-> Program (pk)
    -1-1-> Assumption (pk)
    - createByUser
    - etc.
    Program
    -1-m-> ProgramAssumptionAssociation (independent/optional)
    You could also enable batch-reading or joining on the 1-1 relationship to read the target objects efficiently.

  • Insert/delete many to many join in 9.0.3

    Can anyone tell me a good way to create/delete an intersection row in a many to many relationship? I can do it programmatically in the client, but I'd rather have the middle tier view object or application module handle the code. Currently I'm creating a JClient application but later I will be putting the application in a browser. I don't want to rewrite the code every time I change my client application.
    Thanks

    I forgot to mention that I'm using the BC4J framework.
    Mike

  • There are too many PIN changes associated with this account (Error ID: 30801)

    how to solve this error on app world "There are too many PIN changes associated with this account (Error ID: 30801)" can anyone advice because I follow all the steps to solve it and no one answer me
    I call the customer care using the free number then I call my provider to redirect me to blackberry customer care and no one help me
    so is there any link can show me all the PIN which is assign to my account and manage them
    Please Advice

    Hi and Welcome to the Community!
    Here is a KB that discusses that error:
    KB25553 "There are too many PIN changes associated with this account (Error ID: 30801)" is encountered when attempting to login to BlackBerry App World
    As you see, the way to resolve it is clear, and you seem to have reached some folks in your attempts that were not able to resolve it. Nevertheless, you should not allow them to fob you off...insist that the KB instructs the resolution path and insist that they make good on that.
    aleyadma wrote:
    so is there any link can show me all the PIN which is assign to my account and manage them
    No.
    Good luck and let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • One to Many And Many to Many Association(jdev 11.4 ps3)

    Hi All,
    I was trying different types of ADF-BC implementations, I am stuck with following
    1)     One to Many Association
    a.     Order – OrderItem ( Join over two tables, One OrderVO should have List<OrderItemVO> orderItems
    b.     Employee-Manager (Self Join on the Employee Table, One Employee should have List<Employee> subordinates [0 to *])
    c.     Manager-Employee (Self Join on the Employee Table, One Employee should have List<Employee> managers [ 0 or 1] )
    2)     Many to Many Association
    Would be very helpful if you could provide any Blog published or Some sample implementation of the above.

    Would be very helpful if you tell us which version of jdev you are looking at.
    All this is described in the docs http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcintro.htm#sm0051 to start with and http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcentities.htm#sm0124 to follow up.
    Timo

  • New User Question : Many to Many relationship Association

    Hi
    I am trying to code a many to many relationship between two entities. One of my entity is named View and the other is Column.
    I am trying to use the @JoinTable annotation and for the table property in the annotation I am specifying a table column_view (which I have created in the database).
    My associative table has other fields, apart from the primary key of view and column entities. This makes me feel that my current way of using @JoinTable would not work under this condition and I have to create two onetomany mappings like
    Column -> OnetoMany -> ColumnView <- OnetoMany <- View.
    Am I right in my approach or is there anyother way out to represent such manytomany relationships.

    Why other fields are required in your relationshipt table?
    have only two columns and perform @ManyToMany.
    @JoinTable has to be used only on owning side.
    user (mappedBy ) on the other side
    thanks

  • Seek good method for deleting many to many relationship

    My question is as follows:
    The relationship of Employee and Project is many to many. I set privately owned for employee-project relationship at toplink builder.
    Employee class has a vector of valueholder attribute of Project list.
    I write a function to remove a project relationship from Employee when his is no longer responsible for it.
    public void removeProjectFromEmployee(String employeeId, String projectId)
    throws Exception
    DataSource src = this.getSource();
    Employee emp = getEmployeeById(employeeId);
    if (emp == null) {
    throw new Exception("employee with id " + employeeId + " does not exist.");
    else {
    Vector projectVector = emp.getProjects();
    for (int i=0; i<projectVector.size(); i++){
    Project p=(Project)projectVector.elementAt(i);
    if ((p.getProjId()).equals(projectId)) {
    projectVector.removeElementAt(i);
    emp.setProjects(projectVector);
    src.registerObject(emp);
    src.commit();
    In here, i select the object of the employee and then remove one particular project from the vector. It is working but seemed to be quite stupid. Moreover, i worry about its performance when there are thousands of projects owned by an employee.
    I think it is a very common operation but i am not very familiar with TOPLink at this moment. Could anyone please advise the correct and better way to deal with this situation?
    Thanks

    Hello,
    Try registering your employee in the UnitOfWork before you re-set the collection onto it. This should resolve your problem.
    Note: When you set the collection on the unregistered Employee object, you were modifying a shared, read-only instance of the object, and hence were making transactional changes visible to other threads non-atomically. There are a lot of good reasons why this is a bad thing.
    I hope this helps,
    Christian

  • Hibernate - Spring - problem with mapping (many-to-many)

    Hello,
    I want to map the following situation. I have a table called EDUCATION and a table called SCHOOLS. Between those tables I have an associative table called EDUCATION_SCHOOLS. The (usefull) fields:
    EDUCATION:
    id (long) - PK
    name (varchar)
    versionNr (long)
    SCHOOLS:
    id (long) - PK
    name (varchar)
    versionNr (long)
    EDUCATION_SCHOOLS:
    id (long) - PK
    education_id (long) (FK to EDUCATION.id)
    school_id (long) (FK to SCHOOLS.id)
    name (varchar)
    versionNr (long)
    Their is a Unique Constraint between EDUCATION_SCHOOLS.education_id and EDUCATION_SCHOOLS.school_id.
    What I want to be able to do:
    EDUCATION: select, update, insert
    SCHOOLS: select, update, insert
    EDUCATION_SCHOOLS: select, update (only the non-FK fields), insert
    I never want to delete anything in those tables. (and it's never ever going to be an option either)
    Hibernate version:
    Hibernate-Version: 3.0.5
    Mapping documents:
    Education:
    <hibernate-mapping>
         <class name="##.Education" table="EDUCATION">
              <id name="id" column="ID" type="java.lang.Long">
                   <generator class="sequence">
                        <param name="sequence">EDUCATION_SEQ</param>
                   </generator>
              </id>
              <version name="versionNr" column="VERSIONNR" type="long"/>
              <property name="name" column="NAME" type="string" />
            <set name="SCHOOLS" table="EDUCATION_SCHOOLS">
                <key column="EDUCATION_ID" />
                <many-to-many class="##.Schools" column="SCHOOL_ID" lazy="false" />
            </set>
    </hibernate-mapping>
    Schools:
    <hibernate-mapping>
         <class name="##.Schools" table="SCHOOLS">
              <id name="id" column="ID" type="java.lang.Long">
                   <generator class="sequence">
                        <param name="sequence">SCHOOLS_SEQ</param>
                   </generator>
              </id>
              <version name="versionNr" column="VERSIONNR" type="long"/>
              <property name="name" column="NAAM_NAME" type="string" />
            <set name="educations" table="EDUCATION_SCHOOLS" inverse="true" cascade="none">
                <key column="SCHOOL_ID" />
                <many-to-many class="##.Schools" column="SCHOOL_ID" lazy="proxy"/>
            </set>
    </hibernate-mapping>
    Education_schools:
    <hibernate-mapping>
    <class name="##.EducationSchools" table="EDUCATION_SCHOOLS">
               <id name="id" column="ID" type="java.lang.Long" unsaved-value="0">
                   <generator class="sequence">
                        <param name="sequence">SEQ_EDUCATION_SCHOOLS</param>
                   </generator>
              </id>
              <version name="versionNr" column="VERSIONNR" type="long" />
              <many-to-one name="education" class="##.Education" cascade="none" lazy="proxy"
                           column="EDUCATION_ID" not-null="true"/>
            <many-to-one name="schools" class="##.Schools" cascade="none" lazy="proxy"
                        column="SCHOOL_ID" not-null="true"/>  
    </hibernate-mapping>   
    Name and version of the database you are using:
    Oracle XE 10g
    I am able to:
    EDUCATION: select, insert, update
    SCHOOLS: select, insert, update
    EDUCATION_SCHOOLS: select
    Problems:
    EDUCATION_SCHOOLS: when I try to insert, I sometimes get unique constraint violations. (when I should get them, thus I'm trying to insert something that already exists .. but how do I stop Hibernate from Inserting?)
    EDUCATION_SCHOOLS: when I try to update, sometimes it works, but often I get:
    23:03:55,484 [http-8081-1] ERROR be.vlaanderen.lne.vea.epb.ui.struts.EpbExceptionHandler - org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [##.EducationSchools] with identifier [null]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [##.EducationSchools#<null>]
    ex.getMessage() Object of class [##.EducationSchools] with identifier [null]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [##.EducationSchools#<null>]
    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [##.EducationSchools] with identifier [null]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [##.EducationSchools#<null>]
    Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):As you can see from the stacktrace I use Spring for the transactionManager: org.springframework.orm.hibernate3.HibernateTransactionManager in which I use e sessionFactory: org.springframework.orm.hibernate3.LocalSessionFactoryBean
    In my DAO, I try to save with the regular this.getHibernateTemplate().saveOrUpdate that has always worked for me.
    Another problem I have:
    when i update "name" in EDUCATION, the records with that ID are delete from EDUCATION_SCHOOLS ...
    As I am experiencing 3 different problems, I'm pretty sure something is wrong in the mapping files .. however I fail to find out what .. Any input would be greatly appreciated.
    (I translated some class/table-names, that's what the ## cause)
    Edited by: Bart_Blommaerts on Jul 29, 2008 11:53 PM

    Thank you for your input.
    When I try what you suggest, I still get the same error:
    16:39:30,406 [http-8081-1] ERROR ###.EpbExceptionHandler - org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [###.EducationSchools] with identifier [2]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]
    ex.getMessage() Object of class [###.EducationSchools] with identifier [2]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]
    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [###.EducationSchools] with identifier [2]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]
    Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]If you had to map the database tables, I'm trying to map, how would you do it?

  • Creating data in a many-to-many-relationship

    Hello,
    we really have problems in implementing a JClient dialog based on BC4J for creating data in a many to many relationship - especially with cascade delete on both sides.
    Simplified our tables look like:
    create table A_TABLE
    A_ID VARCHAR2(5) not null,
    A_NAME VARCHAR2(30) not null,
    constraint PK_A_TABLE primary key (A_ID),
    constraint UK_A_TABLE unique (A_NAME)
    create table B_TABLE
    B_ID VARCHAR2(5) not null,
    B_NAME VARCHAR2(30) not null,
    constraint PK_B_TABLE primary key (B_ID),
    constraint UK_B_TABLE unique (B_NAME)
    create table AB_TABLE
    A_ID VARCHAR2(5) not null,
    B_ID VARCHAR2(5) not null,
    constraint PK_AB_TABLE primary key (A_ID, B_ID),
    constraint FK_AB_A foreign key (A_ID) references A_TABLE (A_ID) on delete cascade,
    constraint FK_AB_B foreign key (B_ID) references B_TABLE (B_ID) on delete cascade
    Could JDev Team please provide a BC4J/JClient sample that performs the following task:
    The dialog should use A_TABLE as master and AB_TABLE as detail. The detail displays the names associated with the IDs. Next to AB_TABLE should be a view of B_TABLE which only displays rows that are currently not in AB_TABLE. Two buttons are used for adding and removing rows in AB_TABLE. After adding or removing rows in the intersection the B_TABLE view should be updated. The whole thing should work in the middle and client tier. This means no database round trips after each add/remove, no posts for AB_TABLE and no query reexecution for B_TABLE until commit/rollback.
    This is a very common szenario: For an item group (A_TABLE) one can select and deselect items (AB_TABLE) from a list of available items (B_TABLE). Most of JDeveloper4s wizards use this. They can handle multi/single selections, selections from complex structures like trees and so on. Ok, the wizards are not based on BC4J - or? How can we do it with BC4J?
    Our main problems are:
    1. Updating the view of B_TABLE after add/remove reflecting the current selection
    2. A good strategy for displaying the names instead of the IDs (subqueries or joining the three tables)
    3. A JBO-27101 DeadEntityAccessException when removing an existing row from AB_TABLE and adding it again
    Other problems:
    4. We get a JBO-25030 InvalidOwnerException when creating a row in AB_TABLE. This is caused by the composition. We workaround this using createAndInitRow(AttributeList) on the view object (instead of create()). This is our add-Action:
    ViewObject abVO = panelBinding.getApplicationModule().findViewObject("ABView");
    ViewObject bVO = panelBinding.getApplicationModule().findViewObject("BView");
    Row bRow = bVO.getCurrentRow();
    NameValuePairs attribList = new NameValuePairs(
    new String[]{"BId"}, new Object[]{bRow.getAttribute("BId")});
    Row newRow = abVO.createAndInitRow(attribList);
    abVO.insertRow(newRow);
    5. After inserting the new row the NavigationBar has enabled commit/rollback buttons and AB_TABLE displays the row. But performing a commit does nothing. With the following statement after insertRow(newRow) the new row is created in the database:
    newRow.setAttribute("BId", bRow.getAttribute("BId"));
    Please give us some help on this subject.
    Best regards
    Michael Thal

    <Another attempt to post a reply. >
    Could JDev Team please provide a BC4J/JClient sample
    that performs the following task:
    The dialog should use A_TABLE as master and AB_TABLE
    as detail. The detail displays the names associated
    with the IDs. Next to AB_TABLE should be a view of
    B_TABLE which only displays rows that are currently
    not in AB_TABLE. Two buttons are used for adding and
    removing rows in AB_TABLE. After adding or removing
    rows in the intersection the B_TABLE view should be
    updated. The whole thing should work in the middle
    and client tier. This means no database round trips
    after each add/remove, no posts for AB_TABLE and no
    query reexecution for B_TABLE until commit/rollback.
    This is a very common szenario: For an item group
    (A_TABLE) one can select and deselect items
    (AB_TABLE) from a list of available items (B_TABLE).
    Most of JDeveloper4s wizards use this. They can
    handle multi/single selections, selections from
    complex structures like trees and so on. Ok, the
    wizards are not based on BC4J - or? How can we do it
    with BC4J?
    Our main problems are:
    1. Updating the view of B_TABLE after add/remove
    reflecting the current selectionYou should be able to use insertRow() to insert the row into proper collection.
    However to remove a row only from the collection, you need to add a method on the VO subclasses (and perhaps export this method so that the client side should see it) to unlink a row from a collection (but not remove the associated entities from the cache).
    This new method should use ViewRowSetImpl.removeRowAt() method to remove the row entry at the given index from it's collection. Note that this is an absolute index and not a range index in the collection.
    2. A good strategy for displaying the names instead
    of the IDs (subqueries or joining the three tables)You should join the three tables by using reference (and perhaps readonly) entities.
    3. A JBO-27101 DeadEntityAccessException when
    removing an existing row from AB_TABLE and adding it
    againThis is happening due to remove() method on the Row which is marking the row as removed. Attempts to add this row into another collection will throw a DeadEntityAccessException.
    You may 'remove the row from it's collection, then call 'Row.refresh' on it to revert the entity back to undeleted state.
    >
    Other problems:
    4. We get a JBO-25030 InvalidOwnerException when
    creating a row in AB_TABLE. This is caused by the
    composition. We workaround this using
    createAndInitRow(AttributeList) on the view object
    (instead of create()). This is our add-Action:
    ViewObject abVO =
    O =
    panelBinding.getApplicationModule().findViewObject("AB
    iew");
    ViewObject bVO =
    O =
    panelBinding.getApplicationModule().findViewObject("BV
    ew");
    Row bRow = bVO.getCurrentRow();
    NameValuePairs attribList = new NameValuePairs(
    new String[]{"BId"}, new
    String[]{"BId"}, new
    Object[]{bRow.getAttribute("BId")});
    Row newRow = abVO.createAndInitRow(attribList);
    abVO.insertRow(newRow);This is a handy approach. Note that Bc4j framework does not support dual composition where the same detail can be owned by two or more masters. In those cases, you also need to implement post ordering to post the masters before the detail (and reverse ordering for deletes).
    >
    5. After inserting the new row the NavigationBar has
    enabled commit/rollback buttons and AB_TABLE displays
    the row. But performing a commit does nothing. With
    the following statement after insertRow(newRow) the
    new row is created in the database:
    newRow.setAttribute("BId",
    d", bRow.getAttribute("BId"));This bug in JDev 903 was fixed and a patch set (9.0.3.1) is (I believe) available now via MetaLink.
    >
    >
    Please give us some help on this subject.
    Best regards
    Michael Thal

  • EF database first cascades delete despite cascade is restricted in db and edmx setting End1/2 OnDelete = "None"

    We are developing with Visual Studio 2013, Entity Framework 5, Oracle DB 11 via ODP.NET managed driver.
    The edmx is generated/updated from database (database first). We generate POCO object using standard T4.
    We have 2 tables with a master-detail foreign key relation, one to many. The foreign key in database does _not_ allow cascade deletes, so when you delete master row via SQL, you get error " ... child record found ... ".
    The problem now is:
    In Entity Framework, when i delete a record from the master table, then EF also deletes all corresponding detail records from the detail table! The restriction of the foreign key in database is ignored.
    In edmx diagram, the properies End1 OnDelete / End2 OnDelete are set to "None", so i expect that on delete of a master row, EF should throw an error if detail rows exists.
    How can i disable the cascading of the delete?
    Here is the FK definition in edmx:
            <Association Name="USR_USER_ROLES_ROLES_FK">
              <End Role="USR_ROLES" Type="Self.USR_ROLES" Multiplicity="1" />
              <End Role="USR_USER_ROLES" Type="Self.USR_USER_ROLES" Multiplicity="*" />
              <ReferentialConstraint>
                <Principal Role="USR_ROLES">
                  <PropertyRef Name="GES" />
                  <PropertyRef Name="PROJ" />
                  <PropertyRef Name="ROLE_NAME" />
                </Principal>
                <Dependent Role="USR_USER_ROLES">
                  <PropertyRef Name="GES" />
                  <PropertyRef Name="PROJ" />
                  <PropertyRef Name="ROLE_NAME" />
                </Dependent>
              </ReferentialConstraint>
            </Association> 
     The delete of master row is done by calling:
    ivDbCtx.USR_Roles.Local.Remove(role); // ivDbCtx is the DbContext, USR_Roles is the collection, role is the POCO object to be deleted.
    Thank you very much for your help!
    Udo

    Hello,
    For issues regarding ODP.NET managed driver, I would suggest you posting to oracle entity framework forum:
    https://community.oracle.com/communications
    There are oracle entity framework expects who will help you better.
    Thanks for your understanding.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • Can I have some iWeb sites on one computer & some on another?

    I've been using iWeb to creat both personal and business sites for myself. I've got about six sites and I'd like to control the business ones from my work computer and my personal ones from my home computer. Can I do this? I had copied the files over

  • Distorted audio on Mac but not on PC

    Hi everyone, My colleague recorded audio to a Captivate project on his PC and it sounded great. When I opened and previewed the project on my Mac, the audio came in with microphone distortions for certain phrases (sounds like he was too close to the

  • How to read Ibase and component details and save to a file in presentation

    Hi Experts, I am developing a report to download Ibase and Component details along with warranty and component details to presentation server. So it is appreciated and rewarded If you provide any Standard FMS and any code done b4 by you to download t

  • How to reduce classpath size ??

    I have an application in which the classpath size has reached its maximum limit. I start my web logic server using perl scripts and the classpath is defined in that script. I want to add an additional path to my classpath but i am not able to do so .

  • Selected Values not displaying in Multiselect Prompt

    Hi all, We are having reports with Multiselect Prompts. When we select values , we are unable to see the corresponding values. Is their any rule like Multiselect Prompt won't work if there are Null values in it..