class must define a set accessor
sanshew Sep 15, 2005 5:14 PMI dont get this, This is my code
in my ejb-jar.xml file
Item Bean deployment descriptor
<display-name>Item</display-name>
<ejb-name>Item</ejb-name>
<local-home>edu.rice.rubis.beans.ItemLocalHome</local-home>
edu.rice.rubis.beans.ItemLocal
<ejb-class>edu.rice.rubis.beans.ItemBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>edu.rice.rubis.beans.ItemPK</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>ItemBean</abstract-schema-name>
<cmp-field>
<field-name>id</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<cmp-field>
<field-name>description</field-name>
</cmp-field>
<cmp-field>
<field-name>initialPrice</field-name>
</cmp-field>
<cmp-field>
<field-name>quantity</field-name>
</cmp-field>
<cmp-field>
<field-name>reservePrice</field-name>
</cmp-field>
<cmp-field>
<field-name>buyNow</field-name>
</cmp-field>
<cmp-field>
<field-name>nbOfBids</field-name>
</cmp-field>
<cmp-field>
<field-name>maxBid</field-name>
</cmp-field>
<cmp-field>
<field-name>startDate</field-name>
</cmp-field>
<cmp-field>
<field-name>endDate</field-name>
</cmp-field>
<cmp-field>
<field-name>sellerId</field-name>
</cmp-field>
<cmp-field>
<field-name>categoryId</field-name>
</cmp-field>
<cmp-field>
<field-name>links</field-name>
</cmp-field>
<cmp-field>
<field-name>upc</field-name>
</cmp-field>
<ejb-local-ref>
This is the reference to the id manager
<ejb-ref-name>ejb/IDManager</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>edu.rice.rubis.beans.IDManagerLocalHome</local-home>
edu.rice.rubis.beans.IDManagerLocal
<ejb-link>IDManager</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
This is the reference to the user bean
<ejb-ref-name>ejb/User</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>edu.rice.rubis.beans.UserLocalHome</local-home>
edu.rice.rubis.beans.UserLocal
<ejb-link>User</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
This is the reference to the category
bean
<ejb-ref-name>ejb/Category</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>edu.rice.rubis.beans.CategoryLocalHome</local-home>
edu.rice.rubis.beans.CategoryLocal
<ejb-link>Category</ejb-link>
</ejb-local-ref>
<resource-ref>
<res-ref-name>jdbc/rubis</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<query-method>
<method-name>findBySeller</method-name>
<method-params>
<method-param>java.lang.Integer</method-param>
</method-params>
</query-method>
<ejb-ql>
SELECT OBJECT(i)
FROM ItemBean i
WHERE i.sellerId = ?1
</ejb-ql>
<query-method>
<method-name>findByCategory</method-name>
<method-params>
<method-param>java.lang.Integer</method-param>
</method-params>
</query-method>
<ejb-ql>
SELECT OBJECT(i)
FROM ItemBean i
WHERE i.categoryId = ?1
</ejb-ql>
<query-method>
<method-name>findAllItems</method-name>
<method-params/>
</query-method>
<ejb-ql>
SELECT OBJECT(i)
FROM ItemBean i
</ejb-ql>
in my jbosscmp-jdbc file :
<ejb-name>Item</ejb-name>
<table-name>items</table-name>
<cmp-field>
<field-name>id</field-name>
<column-name>id</column-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
<column-name>name</column-name>
</cmp-field>
<cmp-field>
<field-name>description</field-name>
<column-name>description</column-name>
</cmp-field>
<cmp-field>
<field-name>initialPrice</field-name>
<column-name>initial_price</column-name>
</cmp-field>
<cmp-field>
<field-name>quantity</field-name>
<column-name>quantity</column-name>
</cmp-field>
<cmp-field>
<field-name>reservePrice</field-name>
<column-name>reserve_price</column-name>
</cmp-field>
<cmp-field>
<field-name>buyNow</field-name>
<column-name>buy_now</column-name>
</cmp-field>
<cmp-field>
<field-name>nbOfBids</field-name>
<column-name>nb_of_bids</column-name>
</cmp-field>
<cmp-field>
<field-name>maxBid</field-name>
<column-name>max_bid</column-name>
</cmp-field>
<cmp-field>
<field-name>startDate</field-name>
<column-name>start_date</column-name>
</cmp-field>
<cmp-field>
<field-name>endDate</field-name>
<column-name>end_date</column-name>
</cmp-field>
<cmp-field>
<field-name>sellerId</field-name>
<column-name>seller</column-name>
</cmp-field>
<cmp-field>
<field-name>categoryId</field-name>
<column-name>category</column-name>
</cmp-field>
<cmp-field>
<field-name>links</field-name>
<column-name>links</column-name>
</cmp-field>
<cmp-field>
<field-name>upc</field-name>
<column-name>upc</column-name>
</cmp-field>
and in my ItemBean.java class
package edu.rice.rubis.beans;
import java.rmi.*;
import javax.ejb.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.GregorianCalendar;
import java.util.Collection;
/**
* ItemBean is an entity bean with "container managed persistence".
* The state of an instance is stored into a relational database.
* The following table should exist:
*
* CREATE TABLE items (
* id INTEGER UNSIGNED NOT NULL UNIQUE,
* name VARCHAR(100),
* description TEXT,
* initial_price FLOAT UNSIGNED NOT NULL,
* quantity INTEGER UNSIGNED NOT NULL,
* reserve_price FLOAT UNSIGNED DEFAULT 0,
* buy_now FLOAT UNSIGNED DEFAULT 0,
* nb_of_bids INTEGER UNSIGNED DEFAULT 0,
* max_bid FLOAT UNSIGNED DEFAULT 0,
* start_date DATETIME,
* end_date DATETIME,
* seller INTEGER,
* category INTEGER,
* PRIMARY KEY(id),
* INDEX seller_id (seller),
* INDEX category_id (category)
* );
*
* @author Emmanuel Cecchet and
Julie Marguerite
* @version 1.1
*/
public abstract class ItemBean implements EntityBean
{
private EntityContext entityContext;
private transient boolean isDirty; // used for the isModified
function
/****************************/
/* Abstract accessor methods*/
/****************************/
/**
* Set item id.
*
* @since 1.0
*/
public abstract void setId(Integer id);
/**
* Get item id.
*
* @return item id
* @since 1.0
*/
public abstract Integer getId();
/**
* Get item name. This description is usually a short description of
the item.
*
* @return item name
* @since 1.0
*/
public abstract String getName();
/**
* Get item description . This is usually an HTML file describing the
item.
*
* @return item description
* @since 1.0
*/
public abstract String getDescription();
/**
* Get item initial price set by the seller.
*
* @return item initial price
* @since 1.0
*/
public abstract float getInitialPrice();
/**
* Get how many of this item are to be sold.
*
* @return item quantity
* @since 1.0
*/
public abstract int getQuantity();
/**
* Get item reserve price set by the seller. The seller can refuse to
sell if reserve price is not reached.
*
* @return item reserve price
* @since 1.0
*/
public abstract float getReservePrice();
/**
* Get item Buy Now price set by the seller. A user can directly by
the item at this price (no auction).
*
* @return item Buy Now price
* @since 1.0
*/
public abstract float getBuyNow();
/**
* Get item maximum bid (if any) for this item. This value should be
the same as doing SELECT MAX(bid) FROM bids WHERE item_id=?
*
* @return current maximum bid or 0 if no bid
* @since 1.1
*/
public abstract float getMaxBid();
/**
* Get number of bids for this item. This value should be the same as
doing SELECT COUNT(*) FROM bids WHERE item_id=?
*
* @return number of bids
* @since 1.1
*/
public abstract int getNbOfBids();
/**
* Start date of the auction in the format 'YYYY-MM-DD hh:mm:ss'
*
* @return start date of the auction
* @since 1.0
*/
public abstract String getStartDate();
/**
* End date of the auction in the format 'YYYY-MM-DD hh:mm:ss'
*
* @return end date of the auction
* @since 1.0
*/
public abstract String getEndDate();
/**
* Give the user id of the seller
*
* @return seller's user id
* @since 1.0
*/
public abstract Integer getSellerId();
/**
* Give the category id of the item
*
* @return item's category id
* @since 1.0
*/
public abstract Integer getCategoryId();
/**
* Give the links of the item
*
* @return item's links
* @since 1.0
*/
public abstract Integer getLinks();
/**
* Give the UPC of the item
*
* @return item's UPC
* @since 1.0
*/
public abstract Integer getUpc();
/**
* Set a new item name
*
* @param newName item name
* @since 1.0
*/
public abstract void setName(String newName);
/**
* Set a new item description
*
* @param newDescription item description
* @since 1.0
*/
public abstract void setDescription(String newDescription);
/**
* Set a new initial price for the item
*
* @param newInitialPrice item initial price
* @since 1.0
*/
public abstract void setInitialPrice(float newInitialPrice);
/**
* Set a new item quantity
*
* @param qty item quantity
* @since 1.0
*/
public abstract void setQuantity(int qty);
/**
* Set a new reserve price for the item
*
* @param newReservePrice item reserve price
* @since 1.0
*/
public abstract void setReservePrice(float newReservePrice);
/**
* Set a new Buy Now price for the item
*
* @param newBuyNow item Buy Now price
* @since 1.0
*/
public abstract void setBuyNow(float newBuyNow);
/**
* Set item maximum bid. This function checks if newMaxBid is greater
* than current maxBid and only updates the value in this case.
*
* @param newMaxBid new maximum bid
* @since 1.1
*/
public abstract void setMaxBid(float newMaxBid);
/**
* Set the number of bids for this item
*
* @param newNbOfBids new number of bids
* @since 1.1
*/
public abstract void setNbOfBids(int newNbOfBids);
/**
* Set a new beginning date for the auction
*
* @param newDate auction new beginning date
* @since 1.0
*/
public abstract void setStartDate(String newDate);
/**
* Set a new ending date for the auction
*
* @param newDate auction new ending date
* @since 1.0
*/
public abstract void setEndDate(String newDate);
/**
* Set a new seller identifier. This id must match
* the primary key of the users table.
*
* @param id seller id
* @since 1.0
*/
public abstract void setSellerId(Integer id);
/**
* Set a new category identifier. This id must match
* the primary key of the category table.
*
* @param id category id
* @since 1.0
*/
public abstract void setCategoryId(Integer id);
/**
* Set a new link
*
* @param newLinks item links
* @since 1.0
*/
public abstract void setLinks(String newLinks);
/**
* Set a new item UPC
*
* @param newUpc item UPC
* @since 1.0
*/
public abstract void setUpc(String newUpc);
/*****************/
/* relationships */
/*****************/
// This entity bean has a one to many relationship with the Bid
entity.
// public abstract Collection getBids();
// public abstract void setBids(Collection bids);
/*********************/
/* ejbSelect methods */
/*********************/
/**
* Get the first maxToCollect bids for an item sorted from the
* maximum to the minimum.
*
* @param maxToCollect number of bids to collect
* @param itemId item id
*
* @return Collection of bids
* @exception FinderException if an error occurs
* @since 1.0
*/
// public abstract Collection ejbSelectItemQtyMaxBid(int maxToCollect,
Integer itemId) throws FinderException;
/**
* Get the bid history for an item sorted from the last bid to the
* first bid (oldest one).
*
* @param itemId item id
*
* @return Vector of bids primary keys or null if no bids
* @exception RemoteException if an error occurs
* @since 1.0
*/
// public abstract Collection ejbSelectItemBidHistory(Integer itemId)
throws FinderException;
/*****************/
/* other methods */
/*****************/
/**
* Call the corresponding ejbSelect method.
*/
// public Collection getItemQtyMaxBid(int maxToCollect, Integer
itemId) throws FinderException
// {
// return ejbSelectItemQtyMaxBid(maxToCollect, itemId);
// }
/**
* Call the corresponding ejbSelect method.
*/
// public Collection getItemBidHistory(Integer itemId) throws
FinderException
// {
// return ejbSelectItemBidHistory(itemId);
// }
/**
* Get the seller's nickname by finding the Bean corresponding
* to the user.
*
* @return nickname
* @since 1.0
*/
public String getSellerNickname()
{
Context initialContext = null;
try
{
initialContext = new InitialContext();
}
catch (Exception e)
{
System.err.print("Cannot get initial context for JNDI: " + e);
return null;
}
// Try to find the user nick name corresponding to the sellerId
UserLocalHome uHome;
try
{
uHome =
(UserLocalHome)initialContext.lookup("java:comp/env/ejb/User");
}
catch (Exception e)
{
System.err.print("Cannot lookup User: " +e);
return null;
}
try
{
UserLocal u = uHome.findByPrimaryKey(new UserPK(getSellerId()));
return u.getNickName();
}
catch (Exception e)
{
System.err.print("This user does not exist (got exception: "
+e+")");
return null;
}
}
/**
* Get the category name by finding the Bean corresponding to the
category Id.
*
* @return category name
* @since 1.0
*/
public String getCategoryName()
{
Context initialContext = null;
try
{
initialContext = new InitialContext();
}
catch (Exception e)
{
System.err.print("Cannot get initial context for JNDI: " + e);
return null;
}
// Try to find the CategoryName corresponding to the categoryId
CategoryLocalHome cHome;
try
{
cHome =
(CategoryLocalHome)initialContext.lookup("java:comp/env/ejb/Category");
}
catch (Exception e)
{
System.err.print("Cannot lookup Category: " +e);
return null;
}
try
{
CategoryLocal c = cHome.findByPrimaryKey(new
CategoryPK(getCategoryId()));
return c.getName();
}
catch (Exception e)
{
System.err.print("This category does not exist (got exception: "
+e+")");
return null;
}
}
}
and keep getting this error from JBOSS
2005-09-15 13:37:36,899 WARN [org.jboss.ejb.EJBDeployer.verifier] EJB
spec violation:
Bean : Item
Section: 10.6.2
Warning: The entity bean class must define a set accessor for each CMP
field.
Info : Field: links
2005-09-15 13:37:36,899 WARN [org.jboss.ejb.EJBDeployer.verifier] EJB
spec violation:
Bean : Item
Section: 10.6.2
Warning: The entity bean class must define a set accessor for each CMP
field.
Info : Field: upc
any help will be awsome.
Thanks.