[jboss-user] [JBoss Seam] - Re: Seam component as converter with EntityManager/Persisten
bfo81
do-not-reply at jboss.com
Thu Aug 24 04:28:30 EDT 2006
Well, those converter beans are really weird...
In the getAsObject method you might load entities over and over via the em. So I decided to cache them (I even have a method to check if something is dirty).
Well this cache is a inner class with a HashMap. It works well, entities get filled into the cache and retrieved from there. BUT: Only during one page invocation.
As soon as I enter a page later, the cache is empty... or let's say, it's even a different cache (I logged the hashcode). This is the same problem like with the EntityManager. It gets lost after first invocation. And the funny thing: I even don't know how it's being reconstructed. I added a debug message to the cache's constructor, but it gets only called once. The next times the cache gets instantiated it overrides my constructor. This is extremely weird ^^.
However, to draw the conclusion. If you have a converter with some kind of property
...
| @Name("theConverter")
| ...
| public class TheConverter ... {
|
| private SomeThing something = new SomeThing();
|
| public Object getAsObject(...) {
| use(something);
| ...
"something" will be a different instance for every page invocation. If you want it to be always the same, use the Singleton pattern, so that the property class manages its instance itself.
| ...
| //use(something); //Not like this!
| use(SomeThing.instance()); //But that way!
| public class SomeThing implements Serializable {
| private static SomeThing instance;
| public static SomeThing instance() {
| if (instance == null)
| instance = new SomeThing();
| return instance;
| }
| ....
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3967168#3967168
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3967168
More information about the jboss-user
mailing list