1 Reply Latest reply on Jun 16, 2005 9:15 PM by Emmanuel Bernard

    Setting association with PK knowledge without object loading

    Leos Urban Newbie

      We know primary key of associated object and we need to put it into my entity bean.
      For example: entity Tour contains entity Destination.

      In first step we import all Destinations from text file with loaded xguid as primary key.
      In second step we import Tours (there is Destionation xguid too).
      Does exist some way how to insert Destination into new Tours without loading Destination?
      Correct way with load is:

      Destination d = em.find(Destination.class,xguid);
      Tour t = new Tour();
      t.setDestination(d);
      


      But when is CascadeType set to none, then next way works also:

      Destination d = new Destination();
      d.setId(xguid);
      Tour t = new Tour();
      t.setDestination(d);
      


      This Destination is not inserted into Destinations (CascadeType is none) but association is created (?).

      I dont know if this way is correct...
      Some other way to directly set primary key?

      Leonell