Hi,
I have made added some feature to the way "dependant value objects" are
mapped to table fields.
This is for example when I have a UserBean cmp entity bean that have a
cmp-field address of non primitive type Address, and I want to store each
fields of Address into the database using a specific Jaws feature.
IMHO, with dependant objects being dropped of EJB 2.0, I think this feature
is important because the standard way to that with ejb 2.0 would be to
define a cmp bean for my value object which is really going too far.
Up to now, this was possible with the fields of Address being public.
This is still possible and needed in the special case the dependant value
object is a PrimaryKey class of another enity bean. (IMHO, this is a nice
feature to make relationships between ejb without having do use a remote
interface field because it permits direct sql between tables, and keep an OO
relationship that you loose if you map the pk fields as primtive type.
>From now it is also possible when the fields of Address are private, have
corresponding get/set methods, if Address have a no argument constructor,
and if Address is serializable.
As it is my first commit to jboss, I would like that somebody validate my
work. Let me know of problems and I'll fix them directly. I also read that
somebody have begin to document this feature, I would like to add this in
his document and commit the all to jboss-docs. Keep me inform please.
The preferred way to do it is this:
1. Define address in the cmp bean :
public Address address;
2. Define the dependant value Object that must have a no argument
constructor.
public class Address implements Serializable
{
private String line1;
private String zipCode;
// etc...
public Address() {}
public String getLine1() { return line1; }
public void setLine1(String line1) { this.line1 = line1; }
// etc...
}
3. in ejb-jar, define address as a field
<cmp-field><field-name>address</field-name></cmp-field>
4. in jaws, define how to compose/decompose this dependant value object to
database fields, for example :
<cmp-field>
<field-name>address.line1</field-name>
<column-name>addr_line1</column-name>
</cmp-field>
<cmp-field>
<field-name>address.zipCode</field-name>
<column-name>addr_zip</column-name>
</cmp-field>
Be carefull here that the fields that are not mapped will not be taken into
account. I had to choose between this and an automatic mapping feature.
IMHO, an automatic mapping feature is not necessary and could cause
problem/confusion.
To finish, you have to know that it is recursive, you can so have for
example address.zipCode.code with a Zip object.
That's all folks.
Future possible improvements :
1. Multiple tables definition for one bean (Borland permit that, does JBoss
want that ?)
2. Collection type support for dependant value objects (one bean to multiple
rows/multiple tables) (become quickly a nightmare if you have a cmp bean
that have a COllection of dependant value objects that each have a
Collection of dvo, etc... or if you want to be able to do lazy
loading/dirty checking on the collection, ... ; and with ejb-relationship of
ejb 2.0 is it "really" needed ?)
Vincent.
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user