You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 22 Members of 4546 |
| Forum: Seam Users |
21. Jul 2008, 16:05 CET | Link |
Hi,
I'm trying to follow the dvd example, but in the search updateResults() I need to do few more things to calculate prices.
so I have:
@Stateful
@Name("search")
public class SearchAction implements Search, Serializable{
@Begin(join = true)
public String doSearch(){
...
}
public void updateResults() {
if(this.customer!=null) {
for(Stock stock : resultList) {
StockPrice price = new StockPrice(stock, this.customer, new BigDecimal(1));
price.get(this.entityManager); //get method uses at least few times entityManager to do query to db
stock.setCustomerPrice(price.getItemPrice());
}
}
}
}
StockPrice.get method heavily uses the entityManager, but sometimes I'm getting:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
the question is can I pass as argument entityManager?
Sorry for so stupid question.
Tomek
How do you declare your EntityManager? The error might occur because you're not using the Seam Managed Persistence Context (also refered as SMPC). To have a SMPC, you need to do something like @In EntityManager entityManagerName Where entityManagerName is declared in WEB-INF/component.xml like that
in components.xml I have:
<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/WebshopEntityManagerFactory"/>Anyway just found my problem, I have created instance of Contact class in an authenticate method,
@Name(contact) @Entity public class Contact{ @ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY) @JoinColumn(name="customer_code", referencedColumnName="code", nullable=false) private Customer customer; }and used @Out annotation to be able use it later:
@Out(required=false, scope = ScopeType.SESSION) private Contact contact;but then when I try to call method doSearch:
and use in it:I'm getting the error above. Could you suggest what would be the best approach? - start the long running conversation in the authenticate method? - or start it on doSearch() and reselect Contact from db?
Thanks for your time, and sorry for my English.
Tomek
You could always merge the Contact into the SMPC when doSearch is invoked:
or take a look at this alternative.
Hope it helps.
--------------------------------------------------
Check my blog to find announcements on Seam Framework: Experience the Evolution of Java EE
Great, I tried first solution for now and it works!
Thanks