jpa persist , merge ?

J

john

I have entity A and it has FK to entity B.(B is some lookup table)

when I do this

A a = new A();
B b = new B();
b.setId(1L);
a.setB(b);

and then i call em.persist(a) jpa generates first SQL select statement
to get entity B, and then it generates SQL insert, but when I call
em.merge(b), there is only SQL insert statement ? Why does persist()
needs to check if FK that is set to A exists, and merge() doesn't ?


THANKS IN ADVANCE.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top