MountainClimb / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

FKListStore throws exception when calling size on unowned empty list #310

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When calling the size() method of a List that is empty a 
NucleusFatalUserException is thrown. If there is at least a single child entity 
in the list it works as expected.

The exception:

NucleusFatalUserException("Dont currently support ordered lists that are 
unowned");

What steps will reproduce the problem?
1. Create an unowned @OneToMany List that is empty
2. Try to access the size method of that child list.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
GAE 1.7.3/ JPA v2, datanucleus-appengine-2.1.2-SNAPSHOT.jar

I created a snapshot build to help resolve a previous bug. 

Please provide any additional information below.

@Entity
public class Establishment extends DatastoreObject {

    @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }, mappedBy = "establishment", orphanRemoval = true)
    private List<EstablishmentMenu> menus = new ArrayList<EstablishmentMenu>();

}

@Entity
public class EstablishmentMenu extends DatastoreObject {

    @ManyToOne
    private Establishment establishment;
}

public List<EstablishmentMenu> findMenusForEstablishment(Long establishmentId, 
int start, int length) {
        EntityManager em = ThreadLocalPersistenceManager.getEntityManager();

        List<EstablishmentMenu> menus = null;

        Establishment establishment = em.find(Establishment.class, establishmentId);

        List<EstablishmentMenu> allMenus = establishment.getMenus();

            // !! Added the isEmpty check so that the NucluesFatalUserException would not be thrown, otherwise
            // allMenus.size() will throw "Dont currently support ordered lists that are unowned"
        if (! allMenus.isEmpty()) {
            int end = start + length;
            if (end > allMenus.size()) {
                end = allMenus.size();
            }

            menus = allMenus.subList(start, end);
        }

        return menus;
    }

Original issue reported on code.google.com by chris.hi...@gmail.com on 24 Dec 2012 at 3:59