ValueObject creation problem


EJB programming & troubleshooting: ValueObject creation problem

  1. ValueObject creation problem (1 messages)

    I have set up two CMP beans AuthorBean and ImageBean that have a 1:1 relation via AuthorBean.getImage() that returns an ImageBeanLocal object. That works perfectly well.

    Now I want to integrate this into a Struts application. Just a simple HTML-form, reading name, description and the image as a byte[]. With Struts I could use a simple ValueObject, with fields for String name, String description and byte[] image, to transfer the data to the AuthorBean. The obvious problem is, that AuthorBean's image field is an ImageBeanLocal not byte[].

    So I tried two solutions:

    1) I set up AuthorBean.setImageContent(byte[]) and byte[] AuthorBean.getImageContent() methods with actual implementations for fetching the related ImageBean and returning/setting it's data. That might work, but if I try to include those methods into the value-object, I get "getImageContent()/setImageContent is undefined" errors in the XDoclet-created AuthorBeanData class.

    2) I created a value object "by hand", that is derived from as simpler generated value object, that only held the name and description fields. That looks like an ugly solution to me.

    Is there any "right" way to handle this situation? Do I have a completly wrong approach? Any help?

    Thanks a lot for your help,

    (Tried to post the classes, but got "The message body is too long"...)
  2. You should have a session facade for this, since I guess you do not access the entity using its remote interface...
    The facade should interface the clients (in this case, the webapp) with the business logic. Usually, value object creating is a per-use case task.

    Cheers and happy coding,