Here are 2 classes. one is called CustomerBean and the other is TicketBean. They are 
both commented with xdoclet and the relation between them is a unidirectional 
1-many-relation (one customer with many tickets). The tables are automaticly created 
by jboss for mysql (example works only for MySQL).

CustomerBean holds all the customerinformation (email, password, lastnamen and 
firstname).
TicketBean holds all the ticketinformation for eg a concert (name of ticket, price and 
number of tickets).

The example isn't finished, but you'll get an idea.

CustomerBean:
/*
  |  * Created on 25-feb-2004
  |  *
  |  */
  | package ejb.entity;
  | 
  | import javax.ejb.CreateException;
  | import javax.ejb.EntityBean;
  | 
  | /**
  |  *
  |  * @ejb.bean
  |  *  cmp-version = "2.x"
  |  *  jndi-name = "ejb/entity/CustomerBean"
  |  *  name = "Customer"
  |  *  primkey-field = "id"
  |  *  schema = "CustomerSchema"
  |  *  type = "CMP" 
  |  *  view-type = "local"
  |  * 
  |  * @ejb.persistence
  |  *  table-name = "Customer"
  |  * 
  |  * @jboss.entity-command
  |  *  name = "mysql-get-generated-keys"
  |  * 
  |  * @ejb.finder
  |  *  signature = "java.util.Collection findAll()"
  |  *  query = "select object(c) from CustomerSchema as c"
  |  * 
  |  * @ejb.finder
  |  *  signature = "ejb.CustomerBean findByEmail(java.lang.String email)"
  |  *  query = "select object(c) from CustomerSchema as c where c.email = ?1"
  |  */
  | public abstract class CustomerBean implements EntityBean {
  | 
  |     /**
  |      * @param email
  |      * @param password
  |      * @param lastname
  |      * @param firstname
  |      * @return
  |      * @throws CreateException
  |      * 
  |      * @ejb.create-method
  |      */
  |     public Integer ejbCreate(String email, String password, String lastname, 
String firstname) throws CreateException {
  |             setEmail(email);
  |             setPassword(password);
  |             setLastname(lastname);
  |             setFirstname(firstname);
  |             return null;
  |     }
  |     
  |     /**
  |      * @throws CreateException
  |      */
  |     public void ejbPostCreate() throws CreateException {            
  |     }
  |     
  |     /**
  |      * @return
  |      *
  |      * @ejb.interface-method 
  |      * @ejb.pk-field
  |      * @ejb.persistence
  |      *  column-name = "id"
  |      *  sql-type = "INT"
  |      * @jboss.persistence
  |      *  auto-increment = "true"      
  |      */
  |     public abstract Integer getId();
  | 
  |     /**
  |      * @param id
  |      */
  |     public abstract void setId(Integer id);
  |     
  |     /**
  |      * @return
  |      * 
  |      * @ejb.interface-method
  |      * @ejb.persistence
  |      *  column-name = "email"
  |      *  sql-type = "varchar"
  |      * @ejb.persistent-field 
  |      */
  |     public abstract String getEmail();
  |     
  |     /**
  |      * @param email
  |      * 
  |      * @ejb.interface-method
  |      */
  |     public abstract void setEmail(String email);
  | 
  |     /**
  |      * @return
  |      * 
  |      * @ejb.interface-method
  |      * @ejb.persistence
  |      *  column-name = "password"
  |      *  sql-type = "varchar"
  |      * @ejb.persistent-field
  |      */     
  |     public abstract String getPassword();
  |     
  |     /**
  |      * @param password
  |      * 
  |      * @ejb.interface-method
  |      */
  |     public abstract void setPassword(String password);
  |     
  |     /**
  |      * @return
  |      * 
  |      * @ejb.interface-method
  |      * @ejb.persistence
  |      *  column-name = "lastname"
  |      *  sql-type = "varchar"
  |      * @ejb.persistent-field
  |      */
  |     public abstract String getLastname();
  |     
  |     /**
  |      * @param lastname
  |      * 
  |      * @ejb.interface-method
  |      */
  |     public abstract void setLastname(String lastname);
  |     
  |     /**
  |      * @return
  |      * 
  |      * @ejb.interface-method
  |      * @ejb.persistence
  |      *  column-name = "firstname"
  |      *  sql-type = "varchar"
  |      * @ejb.persistent-field
  |      */
  |     public abstract String getFirstname();
  | 
  |     /**
  |      * @param firstname
  |      * 
  |      * @ejb.interface-method
  |      */     
  |     public abstract void setFirstname(String firstname);
  |     
  |     /**
  |      * @return 
  |      *
  |      * @ejb.interface-method
  |      *
  |      * @ejb.relation
  |      *  name="CustomerHasTicketsRelation"
  |      *  role-name="the-ticket-of"
  |      *  target-ejb = "Ticket"
  |      *  target-role-name = "the-customer-of"
  |      */
  |     public abstract java.util.Collection getTickets();
  | 
  |     /**
  |      * @param newTickets
  |      *
  |      * @ejb.interface-method
  |      */
  |     public abstract void setTickets(java.util.Collection newTickets);
  | }




TicketBean:
/*
  |  * Created on 25-feb-2004
  |  *
  |  */
  | package ejb.entity;
  | 
  | import javax.ejb.CreateException;
  | import javax.ejb.EntityBean;
  | 
  | /**
  |  * @ejb.bean
  |  *  cmp-version = "2.x"
  |  *  jndi-name = "ejb/entity/TicketBean"
  |  *  name = "Ticket"
  |  *  primkey-field = "id"
  |  *  schema = "TicketSchema"
  |  *  type = "CMP"
  |  *  view-type = "local"
  |  * 
  |  * @ejb.persistence
  |  *  table-name = "Ticket"
  |  * 
  |  * @jboss.entity-command
  |  *  name = "mysql-get-generated-keys"
  |  * 
  |  * @ejb.finder
  |  *  signature = "java.util.Collection findAll()"
  |  *  query = "select object(t) from TicketSchema as t"
  |  */
  | public abstract class TicketBean implements EntityBean {
  | 
  |     /**
  |      * @return
  |      * @throws CreateException
  |      * 
  |      * @ejb.create-method
  |      */
  |     public Object ejbCreate(String name, Double price, Integer count)
  |             throws CreateException {
  |             setName(name);
  |             setPrice(price);
  |             setCount(count);
  |             return null;
  |     }
  | 
  |     /**
  |      * @throws CreateException
  |      */
  |     public void ejbPostCreate() throws CreateException {
  | 
  |     }
  | 
  |     /**
  |      * @return
  |      * 
  |      * @ejb.pk-field
  |      *
  |      * @ejb.persistence
  |      *  column-name = "id"
  |      *  sql-type = "INT"
  |      *
  |      * @jboss.persistence
  |      *  auto-increment = "true"
  |      *
  |      * @ejb.interface-method
  |      */
  |     public abstract Integer getId();
  | 
  |     /**
  |      * @param id
  |      */
  |     public abstract void setId(Integer id);
  | 
  |     /**
  |      * @return
  |      * 
  |      * @ejb.interface-method
  |      * @ejb.persistence
  |      *  column-name = "name"
  |      *  sql-type = "varchar"
  |      * @ejb.persistent-field 
  |      */
  |     public abstract String getName();
  |     /**
  |      * @param name
  |      * 
  |      * @ejb.interface-method
  |      */
  |     public abstract void setName(String name);
  | 
  |     /**
  |      * @return
  |      *
  |      * @ejb.interface-method 
  |      * @ejb.persistence
  |      *  column-name = "price"
  |      *  sql-type = "float"
  |      */
  |     public abstract Double getPrice();
  | 
  |     /**
  |      * @param price
  |      * 
  |      * @ejb.interface-method
  |      */
  |     public abstract void setPrice(Double price);
  | 
  |     /**
  |      * @return
  |      * 
  |      * @ejb.interface-method 
  |      * @ejb.persistence
  |      *  column-name = "count"
  |      *  sql-type = "int"
  |      */
  |     public abstract Integer getCount();
  | 
  |     /**
  |      * @param count
  |      * 
  |      * @ejb.interface-method 
  |      */
  |     public abstract void setCount(Integer count);
  | 
  |     /**
  |      * @return
  |      * 
  |      * @ejb.interface-method
  |      * 
  |      * @ejb.relation
  |      *  name = "CustomerHasTicketsRelation"
  |      *  role-name = "the-customer-of"
  |      *  target-ejb = "Customer"
  |      *  target-role-name = "the-ticket-of"
  |      * 
  |      * @jboss.relation         
  |      *  fk-constraint = "false"
  |      *  related-pk-field = "id"
  |      *  fk-column = "customerid"
  |      */
  |     public abstract CustomerLocal getCustomer();
  | 
  |     /**
  |      * @param newCustomer
  |      *
  |      * @ejb.interface-method 
  |      */
  |     public abstract void setCustomer(CustomerLocal newCustomer);
  | }

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3823807#3823807

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3823807


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to