About Question enthuware.oce-jpad.v6.2.514 :

Moderator: admin

Post Reply
__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

About Question enthuware.oce-jpad.v6.2.514 :

Post by __JJ__ »

For some unknown reason this (in particular the line at //1) doesn't throw EntityAlreadyExistsException:

Code: Select all

    public static void main(String[] args) {
        setupY1();
        setupY1A();
        closeEM();        
    }
    
    private static void setupY1() {           
        Y y1= new Y("foo");        
        em.getTransaction().begin();
        em.persist(y1);    
        em.getTransaction().commit();      
    }
    
    private static void setupY1A() {                  
        em.getTransaction().begin();
        Y y1 = em.find(Y.class, 1);
        em.persist(y1);					//1
        em.getTransaction().commit();
    }

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.514 :

Post by admin »

As per Section 3.2.2 of JPA 2.0 spec, it should not throw an exception in your case but just ignore the call because y1 points to an entity that is already managed by the entity manager.
Exception is thrown if you try to persist a new entity with the same PK as an entity that already exists in the DB.
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.514 :

Post by __JJ__ »

OK I see, thanks very much.

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests