fareed
fareed

Reputation: 3072

EJB retrieving duplicate rows

I have a weird problem. When I create rows from the view in the database, it does that fine, and shows very nice. but sometimes it retrieves a duplicate row and whatever row I add the same duplicate row will appear again and again. However, when I redeploy the application the problem is solved and the rows are shown properly again until the entry crashes again resulting in the same problem. I can't figure out what is going on as there are no errors. I'm using EJB 3.0, glassfish 3.1.1, JSF 2.0, EclipseLink, and JavaDB.

the above one is the row in the database, the below one is in the IDE

this is how it looks like in the view

this is my persisting code:

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void create(Carrier carrier) {
            em.persist(c.getObject());
            em.flush();
          }
    }

and this is my retrieving code:

o@Override
public List<CrpPaypoint> getPaypoints() {
    Query q = em.createQuery("SELECT c FROM CrpPaypoint c ORDER BY c.levelOrder.levelOrder");
    List<CrpPaypoint> list = q.getResultList();
    return list;
}


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="hrtestPU" transaction-type="JTA">
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
     <jta-data-source>jdbc/hrdb</jta-data-source>
     <exclude-unlisted-classes>false</exclude-unlisted-classes>
     <properties>
        <property name="eclipselink.ddl-generation" value="create-tables"/>
     </properties>
  </persistence-unit>

Upvotes: 1

Views: 652

Answers (1)

James
James

Reputation: 18379

You seem to be somehow corrupting the objects in the shared cache.

To disable the shared cache see,

http://wiki.eclipse.org/EclipseLink/FAQ/How_to_disable_the_shared_cache%3F

Check how you are adding the objects to the collection, ensure your new objects have unique ids, ensure you are not adding the same object twice, or changing the existing objects.

Include your code for how to edit the objects.

Upvotes: 1

Related Questions