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__ » Sat Sep 22, 2018 5:19 pm

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: 7478
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Sat Sep 22, 2018 9:56 pm

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__ » Sun Sep 23, 2018 9:14 pm

OK I see, thanks very much.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests