• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Composite Key Mapping with OneToMany does not work

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My requirement is as below.

Table: Application(id);

Table: Customer(Id,custid); ID is FK to Application table

Table: Address(Id,custid,addrid); Id and CustId are FK to Customer tab;e

My Mapping between Customer & Address table does not work. My Requirement is to insert Id & CustId in Address table.





Can anybody help me on this
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Does not work" is a pretty vague statement. You'll get more help if you can supply some error messages or something.
 
snehal dave
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 comp_appl_id=? and customerid=?

Instead of inserting a report , a update statement gets fired for address table
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Snehal,

Could you please show the code for inserting these POJOs into the Database ?

Regards,
Naresh Waswani
 
snehal dave
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
It's a tiny ad only because the water is so cold.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic