• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Problem while using JPA, EJB 3.0

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am very new to EJB 3.0 and JPA and while implementation i have got one issue.
In the application i have 3 table say A,B & C. B has a FK relationship with PK of A. So functionality is when i update a record in A, a new record with some more details has to be entered in B. So while enter the data in B, i have to check a user entered value in C. To achieve this i am creating a PK Object of the C to get the uniqueness.
Everything is working fine but when i am running the test cases A record is updating in A, a new Record is inserting in B & a New record is also inserted in C.
So in C i dont want to insert the record but it is going and inserting a new record.
I guess somewhere i am wrong to use cascadeType, please help me if anybody has came such scenario.
Code -
--------
POJO for Table A
----------------------
@OneToOne(cascade = CascadeType.REMOVE, mappedBy = "aId")
private B bColumn;

POJO for Table B
------------------------
@JoinColumns( {
@JoinColumn(name = "C_ID", referencedColumnName = "C_ID", nullable = false),
@JoinColumn(name = "B_VALUE", referencedColumnName = "VALUE", nullable = false, insertable = false, updatable = false) })
@ManyToOne
private EnumCTable enumCTable;


@JoinColumn(name = "A_ID", referencedColumnName = "A_ID", nullable = false)
@OneToOne(optional = false)
private A aId;


Thanks in Advance,
Shishir



 
shishir choubey
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys i have found the solution for this

Explanation-
If you create a new object, a new object will be inserted. You need to call EntityManager.find() with the id to get the existing object C. You could also call getReference() to just get a reference to the object, which will not access the database.


Thanks,
Shishir
 
brevity is the soul of wit - shakepeare. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic