I'm trying to add a new entity and then after a successful commit, redirect them to the list action.
Here's a summary of what I'm doing:
@Name("offerAction")
@Scope(ScopeType.CONVERSATION)
public class OfferAction implements Serializable {
@In private EntityManager entityManager;
private List<OfferSite> offerSites;
@Factory("offerSites") public void findAllOfferSites() {
offerSites = entityManager.createQuery("select os from OfferSite os " +
"inner join fetch os.offer o " +
"inner join fetch os.site s " +
"inner join fetch o.store st " +
"inner join fetch os.offer.offerType ot").getResultList());
}
private Offer instance;
@Begin(join = true, flushMode = FlushModeType.MANUAL)
public String createOffer() {
instance = new Offer();
createSupportMap();
return EDIT_VIEW;
}
@End public String save() {
persist();
findAllOfferSites();
return LIST_VIEW;
}
@Transactional void persist() {
entityManager.persist();
/* goes through and persists each site and the metadata associated with each offer-site pair. */
persistOfferSites();
entityManager.flush();
entityManager.refresh(instance);
}
}
Here's the part of the offersite entity that I think is giving me the problems:
@Entity
@Table(name = "t_offer_site")
public class OfferSite {
@Embeddable
public static class Id implements Serializable { /* Long offerId, Long siteId */ }
@EmbeddedId
private Id id = new Id();
@ManyToOne
@JoinColumn(name = "offer_id", insertable = false, updatable = false)
private Offer offer;
}
/* assume getters/setters */
}
This saves the Offer object (and its OfferSite metadata) correctly, but when I look at the table displayed from the results of findAllOfferSites() it's missing the Offer data from the OfferSite object that was just added. The OfferSite info displays just fine! The data appears after I completely start a new conversation.
#############################################
# Offer Id # Store Name # Start Date # Site #
#############################################
# 1 # Store 1 # 1/1/09 # 1 #
# 1 # Store 1 # 1/2/09 # 2 #
# # # 1/1/09 # 1 # <- NEWLY INSERTED ROW
#############################################