I've been struggling to get batch gets working with Spring and JPA. I
am basically trying to build a category tree for an e-commerce site.
The issues I am running in to seem to be related to transactions. I
had set my DAO class for the Category entity to be @Transactional.
Everything seemed to be working, till I tried performing a batch get
query based on Max Ross' post (http://gae-java-
persistence.blogspot.com/2009/10/executing-batch-gets.html). The
first error I got said that I was operating on multiple entity groups
in the same transaction. I found this confusing because it listed two
Category entities and their id's. So my first question is:
Can you only operate on one logical record at a time in a
transaction? I figured since I was working on the same entity -
Category, I should be OK. If each instance of a Category is considered
a separate entity group, then I guess the behavior is correct.
My next approach was to remove the @Transactional annotation for the
batch get. When I do this, I now get:
Object Manager has been closed
org.datanucleus.exceptions.NucleusUserException: Object Manager has
been closed
This occurs withing the DAO Method. Here is the code:
@Override
//@Transactional
public List<Category> getCategoriesByIds(List<Long> ids) {
final Query query = entityManager.createQuery(
"SELECT FROM Category c WHERE id = :ids");
query.setParameter("ids", ids);
List<Category> results = query.getResultList();
return results;
}
Note: the @Transactional is commented out
The error occurs right when "query.getResultList()" is called in the
method. I don't understand how the object manager can already be
closed.
I have been calling the above method from a unit test. Any help would
be appreciated.
The entities look like the following:
@Repository
@Entity
public class Category implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long memberId;
private String identifier;
private Boolean markForDelete;
private Date lastUpdate;
@OneToMany(mappedBy = "category", cascade = CascadeType.ALL)
private Set<CategoryDescription> categoryDescriptions = new
HashSet<CategoryDescription>();
.... Getters and Setters
}
@SuppressWarnings("serial")
@Repository
@Entity
public class CategoryDescription implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
@ManyToOne(fetch = FetchType.LAZY)
private Category category;
private String language;
private String name;
private String shortDescription;
private Text longDescription;
private Text note;
private String keywords;
}
@SuppressWarnings("serial")
@Repository
@Entity
public class CategoryRelationship {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long parentCategoryId;
private Long childCategoryId;
private Long catalogId;
private Double sequence;
private Date lastUpdate;
}
Thanks,
Michael
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.