• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

xdoclet value-object tag does not create get method in entity bean's local (EJB, J2EE)

Hi,

the example at http://xdoclet.sourceforge.net/xdoclet/valueobjects.html didn't work for me.

I tried to create the value object pattern

1. MyEntityBean with
Relevant class tags are:
@ejb.bean type = "CMP" cmp-version = "2.x" view-type = "both"
@ejb.value-object name = "MyEntity"

All seems to be generated properly.
The problem is:
The generated MyEntityLocal does not have a getMyEntityValue() - method ! As in the example. ( Example: PersonValue spv = stef.g e t P e r s o n V a l u e ( ) ;)

Q: What did I do wrong?


Thanks,
  Frank

0
hefter1
Asked:
hefter1
  • 4
  • 4
1 Solution
 
hefter1Author Commented:
Thanks  aozarov.
But thats all done. All classes are created except that one method I need.

Frank
0
 
hefter1Author Commented:
One thing is a bit confusing to me.
In the MyEntityCMP the missing method has been created.
How can I use that method? MyEntityCMP inherits from MyEntity but how does that help me?
I can't always cast to the CMP class!?

Btw.: I upgraded to Xdoclet 1.2.3 for these tests.

Frank
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hefter1Author Commented:
I prepared a short example so you can try yourself:


import java.rmi.RemoteException;

import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;

/**
 * @ejb.bean name="MyEntity"
 *           display-name="Name for MyEntity"
 *           description="Description for MyEntity"
 *           jndi-name="ejb/MyEntity"
 *           type="CMP"
 *
 * @ejb.value-object
 *      name = "MyEntity"
 *      match = "*"
 *
 */
public abstract class MyEntity implements EntityBean {

  public MyEntity() {
    super();
  }

  /**
  * @ejb.persistence
  *       column-name="id"
  *         sql-type="VARCHAR"
  * @ejb.pk-field
  * @ejb.interface-method
  */
  public abstract java.lang.String getId();
  public abstract void setId(java.lang.String id);
 
  /**
   * @ejb.value-object
   * @ejb.persistence
   * @ejb.interface-method
   */
  public abstract String getName();
  public abstract void setName(String name);
 
  public void ejbActivate() throws EJBException, RemoteException {}
  public void ejbLoad() throws EJBException, RemoteException {}
  public void ejbPassivate() throws EJBException, RemoteException {}
  public void ejbRemove() throws RemoveException, EJBException, RemoteException {}
  public void ejbStore() throws EJBException, RemoteException {}
  public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}
  public void unsetEntityContext() throws EJBException, RemoteException {}
}

0
 
aozarovCommented:
I can't try it now as I don't have the right system for it.
Is MyEntityCMP a generated class by xdoclets? (normally this happens when you miss javax.ejb.Entity methods that are implements there)
If so you can define your Entity class in the ejb-jar.xml as MyEntityCMP and not as MyEntity (which what xdoclets should do for you as well).
You can also ommit in MyEntity all the "empty methods" such as "public void ejbActivate() throws EJBException, RemoteException {}" which will be defined
in MyEntityCMP. I also expect to find in the ejb object interface (what the ejb home returns) a generated interface that contains the setValueObject, no?
0
 
aozarovCommented:
Hmm, reading again your original question shows that was not the case for you.
Actually if I remember right (I might be wrong and I don't have the right environment to test it) the last time we did that we actually
created the  getMyEntityValue() and  setMyEntityValue(EntityValue value) ourselves in the EJB [and defined it as interface methods] (and just let xdoclets to generated EntityValue class itself).
0
 
hefter1Author Commented:
05/10/2005 03:11PM PDT:
That means the example at http://xdoclet.sourceforge.net/xdoclet/valueobjects.html is wrong!?

05/10/2005 03:00PM PDT:
Yes, the CMP is generated.
No, the interface also has no such method.

The only generated class that has a getxxxValue() method is the CMP class.
(Once again: How can I use the CMP class in an effective way?)

Otherwise I have to adjust the MyEntityLocal with the help of the merge directory? Great! ;-(
Any hint how to deal with that?

Thanks for your help,
  Frank
0
 
aozarovCommented:
Yes, I think that example has an error though as you can see it still defines in the EJB the get/set ValueObject (the set has a wrong name) and specifiy it as interface-method (as I did before)

/**
     * @ejb.interface-method
     */
    public abstract CustomerLightValue getCustomerLightValue();

    /**
     * @ejb.interface-method
     */
    public abstract void setCustomerValue(CustomerValue value);


(Once again: How can I use the CMP class in an effective way?)
The CMP generated class implments methods that you didn't implements in the EJB (like the ejbXXX life cycle methods or in the
example above the getCustomerLightValue abstract method).

In my aproach you don't define them as abstract.
You do something like that:

    /**
     * @ejb.interface-method
     */
    public CustomerLightValue getCustomerLightValue()
    {
         CustomerLightValue vo = new CustomerLightValue(); // this class will be generated by xdoclets
         vo.setId(getId());
         vo.setName(getName());
         ...
         return vo;
    }

    /**
     * @ejb.interface-method
     */
    public void setCustomerLightValue(CustomerLightValue vo)
    {
           if (vo.hasIdChanged()) // or something like that (can't remember exactly)
                seId(vo.getId();
           if (vo.hasNameChanged())
               setName(vo.getName);
         ....
    }


>> Otherwise I have to adjust the MyEntityLocal with the help of the merge directory? Great! ;-(
I don't think you need that if you take my aproach and define those methods as interface method inside your ejb
We couldn't do it any other way which will be simpler.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now