Currently, we have an existing custom DB->obj persistence framework built on top of Session EJB and attributes are strictly represented as a hierarchy of custom domain classes wrapping basic types such as String, Date, TimeStamp, etc. We have not moved to entity EJB because it is too much work to make EJB 2 to support this, having to programmatically translate/wrap/box those attributes.
Can this custom mapping from table columns to custom attribute classes be easily supported in EJB3? [ March 13, 2007: Message edited by: Chu Tan ]
For example, PhoneDomain essentially is just a String. When instantiating or setting the value of PhoneDomain, there are behavior to make sure it is 7 digits or 10 or 11 digits. The toString() method of PhoneDomain will output "X (XXX) XXX-XXXX". [ March 13, 2007: Message edited by: Chu Tan ]
Wow! Very interesting question...my gut reaction is not really.
I think you'd have to define all of the custom classes as embedded objects that are mapped to database tables. Take a look at the @Embeddable annotation for JPA. You can have complex unique identifiers for an entity too, which appears to be what is going on for you!
In any case, interesting architecture! [ March 14, 2007: Message edited by: Reza Rahman ]
Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
posted 13 years ago
You can easily use the getter method on the entity to return the formatted value? Why do you want to create a new type?