posted 12 years ago
Hi Naresh,
below is the code which i am using to persist the Entity
EntityManagerFactory emf=Persistence.createEntityManagerFactory("JPAService");
EntityManager em=emf.createEntityManager();
em.getTransaction().begin();
Application application=new Application();
Customer customer=new Customer();
Address address=new Address();
List addressList=new ArrayList();
addressList.add(address);
customer.address=addressList;
List customerList=new ArrayList();
customerList.add(customer);
application.customer=customerList;
em.persist(application);
em.getTransaction().commit();
and this is what i see in log file
Hibernate: select SEQ_LCT.nextval from dual
insert into APPLICATION(status, id) values (?, ?)
insert into CUSTOMER (FIRSTNAME, GAUR_APPL_FLAG, INITIALNAME, LASTNAME, MIDDLENAME, id, customerid) values (?, ?, ?, ?, ?, ?, ?)
update CUSTOMER set id=? where id=? and customerid=?
update ADDRESS set id=?, CUSTOMERID=? where ADDRESSID=? and id=? and customerid=?
In the code i have not mentioned all the fields of entity .. the Mapping between Application and Customer work fine i.e. i am able to insert primary key of Application table into Customer table .
But between Customer and Address JPA (using Hibernate) does not work , my requirement is to insert both customerid and id from CUSTOMER to ADDRESS table but UPDATE statement gets fired.