1 Reply Latest reply on Jan 19, 2006 6:29 AM by chochis

    Question about perfomance in persistence of objects

    kodaky

      Hello,

      Supose we have an EntityBean called Person.java

      Person.java

      private Long id;
      private String name;
      private Country country;

      A Second Entity obiously is Country :)

      Country.java

      private Long id;
      private String name;

      And finally we have a method called savePerson which uses EJB 3.0 API internally, so


      public savePerson(String name, long countryId) {
      ...
      }

      MI QUESTION:

      We have only countryId, but not the entire object Country, so
      is necesary retrieve first the Country object from database using entitymanager?

      is posible avoid this foo step and use a proxy or what ever you like?

      in hibernate is posible using load() i think, but i like avoid use hibernate api explicity (in my source code)

      thanks in advance

      kodaky

        • 1. Re: Question about perfomance in persistence of objects
          chochis

          You dont have to retrieve the object from the database.

          Pretty simple:

          create a Country object and insert the pk:
          Country country = new Country();
          country.setId(2);

          Then create the person object and insert the contry object:
          Person person = Person();
          person.setCountry(country);

          ....
          Then
          em.persist(person);


          About the load method, with the EntityManager you have to use find
          find retrieves the class of the object and the PK;

          Regards