-
1. Re: Seam design
norman.richards Jan 4, 2007 7:07 PM (in response to monkeyden)I don't understand the motivation. The entity *IS* the lightweight object interact with at all tiers. It is a pojo with state AND behavior and happens to be able to represent data in a relational database.
-
2. Re: Seam design
monkeyden Jan 5, 2007 1:25 PM (in response to monkeyden)I see your point, and I'm certainly starting to subscribe to this line of thinking. The only thing I'm still wondering (which may be a better question for the EJB3 forum) is if there is a way to legally implement non-persistent methods in the entity? I guess this would fall into the "behavior" category, which you mentioned. It would behave something like the @Transient annotation for methods, rather than fields as the doc states.
-
3. Re: Seam design
norman.richards Jan 5, 2007 2:57 PM (in response to monkeyden)What is a "non-persistent method"?
Create an instance of the pojo entity class without involving an entity manager - call all the methods you want and there is no persistence involved. Set fields - it won't get written to the database. The entity manager on gets involved when you specifically ask it to. Again - the entity IS the lightweight object to interact with at all tiers. -
4. Re: Seam design
monkeyden Jan 5, 2007 4:24 PM (in response to monkeyden)When I say "non-persistent method" I'm referring to entity methods which don't have persistable attributes associated with them (i.e. logic only). There is surely a better way of describing it. These methods are actually related to the current state of a PERSISTED entity, so an empty pojo is of little use to them. It's really semantic state-sensitive logic. To explain, consider my other (slightly confusing) post, to which you graciously responded.
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98505
I have an entity, which I have loaded from the EntityManager. It has an Integer attribute named status. Status can be 0 or 1. On the client I want to display "OK" for 0 and "BAD" for 1.
I'm still developing the POC for the solution but it's much simpler than I thought. I just put the "non-persistent methods" in the base class of the entity. Here is a contrived example:public abstract class StatusBase { public abstract Integer getStatus(); public String getStatusText(){ if(getStatus().intValue() == 0){ return "OK"; }else{ return "BAD"; } } }
@Entity @Name("statusExample") @Table(name = "MY_TABLE") public class Status extends StatusBase implements Serializable { public Integer status = null; @Column(name = "STATUS", length = 1, nullable = false) public abstract Integer getStatus(){ return this.status; } }
This way I can still interact with the entity to get the non-persistent value for the view. -
5. Re: Seam design
norman.richards Jan 5, 2007 5:42 PM (in response to monkeyden)Yes, absolutely. Just create your methods - they really are just pojos. If the method happens to look like a JavaBean getter/setter you should mark it as @Transient so that the persistence engine won't get confused.