The reverse engineering tool did create the right entity beans, but if entity 
class had manytomany mappings editorbean went crazy. 
We have ManyToMany mapping where products have related products.
MySQL INNODB Table:
CREATE TABLE `product` (
  `ID` int(11) NOT NULL auto_increment,
  `NAME` varchar(255) NOT NULL default 'unknown',
  `SHOWED` tinyint(1) NOT NULL default '0',
  `CATEGORY_ID` int(11) NOT NULL default '0',
  `PRICE` float NOT NULL default '0',
  `VERSION` int(11) NOT NULL default '0',
  PRIMARY KEY  (`ID`),
  KEY `NAME` (`NAME`),
  KEY `SHOWED` (`SHOWED`),
  KEY `PRICE` (`PRICE`),
  KEY `CATEGORY_ID` (`CATEGORY_ID`),
  CONSTRAINT `product_ibfk_1` FOREIGN KEY (`CATEGORY_ID`) REFERENCES `category` 
(`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `related_products` (
  `ID` int(11) NOT NULL auto_increment,
  `PRODUCT_ID` int(11) NOT NULL default '0',
  `RELATED_ID` int(11) NOT NULL default '0',
  PRIMARY KEY  (`ID`),
  KEY `PRODUCT_ID` (`PRODUCT_ID`),
  KEY `RELATED_ID` (`RELATED_ID`),
  CONSTRAINT `related_products_ibfk_1` FOREIGN KEY (`PRODUCT_ID`) REFERENCES 
`product` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `related_products_ibfk_2` FOREIGN KEY (`RELATED_ID`) REFERENCES 
`product` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Code:

  | 
  | @Name("productEditor")
  | @Stateful
  | @Interceptors(SeamInterceptor.class)
  | public class ProductEditorBean implements ProductEditor {
  | 
  |     @In(create=true)
  |     private EntityManager entityManager;
  | 
  |     @Valid
  |     private Product instance = new Product();
  |     @TransactionAttribute(NOT_SUPPORTED)
  |     public Product getInstance() {
  |        return instance;
  |     }
  |     public void setInstance(Product instance) {
  |        this.instance = instance;
  |     }
  | 
  |     private boolean isNew = true;
  |     @TransactionAttribute(NOT_SUPPORTED)
  |     public boolean isNew() {
  |        return isNew;
  |     }
  |     public void setNew(boolean isNew) {
  |        this.isNew = isNew;
  |     }
  | 
  |     private String doneOutcome = "find";
  |     public void setDoneOutcome(String outcome) {
  |      doneOutcome = outcome;
  |     }
  | 
  |     @In(required=false)
  |     private transient ProductFinder productFinder;
  | 
  |     @In
  |     private transient ResourceBundle resourceBundle;
  |     
  |     @Begin(join=true)
  |     @IfInvalid(outcome=Outcome.REDISPLAY)
  |     public String create() {
  |        if ( entityManager.find(Product.class, instance.getId())!=null )
  |        {
  |           FacesContext.getCurrentInstance().addMessage(null, 
  |                 new FacesMessage(
  |                       resourceBundle.getString("Product_id") + " " +
  |                       resourceBundle.getString("AlreadyExists")
  |                    )
  |              );
  |           return null;
  |        }
  |        entityManager.persist(instance);
  |        isNew = false;
  |        if (instance.getCategory()!=null) {
  |           instance.getCategory().getProducts().add(instance);
  |        }
  |        refreshFinder();
  |        return "editProduct";
  |     }
  | 
  |     @IfInvalid(outcome=Outcome.REDISPLAY)
  |     public String update() {
  |        refreshFinder();
  |        return null;
  |     }
  | 
  |     @End(ifOutcome="find")
  |     public String delete() {
  |        entityManager.remove(instance);
  |        instance.getCategory().getProducts().remove(instance);
  |        refreshFinder();
  |        return doneOutcome;
  |     }
  | 
  |     @End(ifOutcome="find")
  |     public String done() {
  |        if (!isNew) entityManager.refresh(instance);
  |        return doneOutcome;
  |     }
  |     
  |     private void refreshFinder() {
  |        if (productFinder!=null) productFinder.refresh();
  |     }
  | 
  |     @Destroy @Remove
  |     public void destroy() {}
  | 
  |     
  |     @In(create=true)
  |     private transient CategoryEditor categoryEditor;
  |     
  |     public String category() {
  |        categoryEditor.setNew(false);
  |        categoryEditor.setInstance( instance.getCategory() );
  |        categoryEditor.setDoneOutcome("editProduct");
  |        return "editCategory";
  |     }
  | 
  |     @Begin(join=true)
  |     public String selectCategory() {
  |      CONVERSATION.getContext().set("categorySelector",
  |            Component.getInstance("productCategorySelector", true) );
  |         return "selectCategory";
  |     }
  |     
  | 
  |     @DataModel
  |     public List getOffersList() {
  |        return instance == null || instance.getOffers()==null ?
  |              null : new ArrayList( instance.getOffers() );
  |     }
  | 
  |     @DataModelSelection
  |     private Offer selectedOffer;
  | 
  |     @In(create=true)
  |     private transient OfferEditor offerEditor;
  |     
  |     public String createOffer() {
  |        offerEditor.setNew(true);
  |        offerEditor.setInstance( new Offer() );
  |        offerEditor.getInstance().setProduct(instance);
  |        offerEditor.setDoneOutcome( "editProduct" );
  |        return "editOffer";
  |     }
  | 
  |     public String selectOffer() {
  |        offerEditor.setNew(false);
  |        offerEditor.setInstance( selectedOffer );
  |        offerEditor.setDoneOutcome( "editProduct" );
  |        return "editOffer";
  |     }
  |     
  | 
  |     @DataModel
  |     public List getBilllinesList() {
  |        return instance == null || instance.getBilllines()==null ?
  |              null : new ArrayList( instance.getBilllines() );
  |     }
  | 
  |     @DataModelSelection
  |     private Billline selectedBillline;
  | 
  |     @In(create=true)
  |     private transient BilllineEditor billlineEditor;
  |     
  |     public String createBillline() {
  |        billlineEditor.setNew(true);
  |        billlineEditor.setInstance( new Billline() );
  |        billlineEditor.getInstance().setProduct(instance);
  |        billlineEditor.setDoneOutcome( "editProduct" );
  |        return "editBillline";
  |     }
  | 
  |     public String selectBillline() {
  |        billlineEditor.setNew(false);
  |        billlineEditor.setInstance( selectedBillline );
  |        billlineEditor.setDoneOutcome( "editProduct" );
  |        return "editBillline";
  |     }
  |     
  | 
  |     @DataModel
  |     public List getRelatedProductsesForProductIdList() {
  |        return instance == null || 
instance.getRelatedProductsesForProductId()==null ?
  |              null : new ArrayList( 
instance.getRelatedProductsesForProductId() );
  |     }
  | 
  |     @DataModelSelection
  |     private RelatedProducts selectedRelatedProducts;
  | 
  |     @In(create=true)
  |     private transient RelatedProductsEditor relatedproductsEditor;
  |     
  |     public String createRelatedProducts() {
  |        relatedproductsEditor.setNew(true);
  |        relatedproductsEditor.setInstance( new RelatedProducts() );
  |        relatedproductsEditor.getInstance().setProduct(instance);
  |        relatedproductsEditor.setDoneOutcome( "editProduct" );
  |        return "editRelatedProducts";
  |     }
  | 
  |     public String selectRelatedProducts() {
  |        relatedproductsEditor.setNew(false);
  |        relatedproductsEditor.setInstance( selectedRelatedProducts );
  |        relatedproductsEditor.setDoneOutcome( "editProduct" );
  |        return "editRelatedProducts";
  |     }
  |     
  | 
  |     @DataModel
  |     public List getRelatedProductsesForRelatedIdList() {
  |        return instance == null || 
instance.getRelatedProductsesForRelatedId()==null ?
  |              null : new ArrayList( 
instance.getRelatedProductsesForRelatedId() );
  |     }
  | 
  |     @DataModelSelection
  |     private RelatedProducts selectedRelatedProducts;
  | 
  |     @In(create=true)
  |     private transient RelatedProductsEditor relatedproductsEditor;
  |     
  |     public String createRelatedProducts() {
  |        relatedproductsEditor.setNew(true);
  |        relatedproductsEditor.setInstance( new RelatedProducts() );
  |        relatedproductsEditor.getInstance().setProduct(instance);
  |        relatedproductsEditor.setDoneOutcome( "editProduct" );
  |        return "editRelatedProducts";
  |     }
  | 
  |     public String selectRelatedProducts() {
  |        relatedproductsEditor.setNew(false);
  |        relatedproductsEditor.setInstance( selectedRelatedProducts );
  |        relatedproductsEditor.setDoneOutcome( "editProduct" );
  |        return "editRelatedProducts";
  |     }
  |     
  | 
  |     @DataModel
  |     public List getEntriesList() {
  |        return instance == null || instance.getEntries()==null ?
  |              null : new ArrayList( instance.getEntries() );
  |     }
  | 
  |     @DataModelSelection
  |     private Entry selectedEntry;
  | 
  |     @In(create=true)
  |     private transient EntryEditor entryEditor;
  |     
  |     public String createEntry() {
  |        entryEditor.setNew(true);
  |        entryEditor.setInstance( new Entry() );
  |        entryEditor.getInstance().setProduct(instance);
  |        entryEditor.setDoneOutcome( "editProduct" );
  |        return "editEntry";
  |     }
  | 
  |     public String selectEntry() {
  |        entryEditor.setNew(false);
  |        entryEditor.setInstance( selectedEntry );
  |        entryEditor.setDoneOutcome( "editProduct" );
  |        return "editEntry";
  |     }
  |     
  | 
  | }
  | 
  | package ee.digizone.entity;
  | // Generated 7.04.2006 16:52:56 by Hibernate Tools 3.1.0 beta3
  | 
  | import java.util.HashSet;
  | import java.util.Set;
  | import javax.persistence.CascadeType;
  | import javax.persistence.Column;
  | import javax.persistence.Entity;
  | import javax.persistence.FetchType;
  | import javax.persistence.Id;
  | import javax.persistence.JoinColumn;
  | import javax.persistence.ManyToOne;
  | import javax.persistence.OneToMany;
  | import javax.persistence.Table;
  | 
  | 
  | /**
  |  * Product generated by hbm2java
  |  */
  | @Entity
  | @Table(name="product"
  |     ,catalog="digizone"
  | , uniqueConstraints = {  }
  | )
  | 
  | public class Product  implements java.io.Serializable {
  | 
  | 
  |     // Fields    
  | 
  |      private int id;
  |      private int version;
  |      private Category category;
  |      private String name;
  |      private boolean showed;
  |      private float price;
  |      private Set<Offer> offers = new HashSet<Offer>(0);
  |      private Set<Billline> billlines = new HashSet<Billline>(0);
  |      private Set<RelatedProducts> relatedProductsesForProductId = new 
HashSet<RelatedProducts>(0);
  |      private Set<RelatedProducts> relatedProductsesForRelatedId = new 
HashSet<RelatedProducts>(0);
  |      private Set<Entry> entries = new HashSet<Entry>(0);
  | 
  | 
  |     // Constructors
  | 
  |     /** default constructor */
  |     public Product() {
  |     }
  | 
  |  /** minimal constructor */
  |     public Product(int id, Category category, String name, boolean showed, 
float price) {
  |         this.id = id;
  |         this.category = category;
  |         this.name = name;
  |         this.showed = showed;
  |         this.price = price;
  |     }
  |     
  |     /** full constructor */
  |     public Product(int id, Category category, String name, boolean showed, 
float price, Set<Offer> offers, Set<Billline> billlines, Set<RelatedProducts> 
relatedProductsesForProductId, Set<RelatedProducts> 
relatedProductsesForRelatedId, Set<Entry> entries) {
  |         this.id = id;
  |         this.category = category;
  |         this.name = name;
  |         this.showed = showed;
  |         this.price = price;
  |         this.offers = offers;
  |         this.billlines = billlines;
  |         this.relatedProductsesForProductId = relatedProductsesForProductId;
  |         this.relatedProductsesForRelatedId = relatedProductsesForRelatedId;
  |         this.entries = entries;
  |     }
  |     
  | 
  |    
  |     // Property accessors
  |     @Id
  |     @Column(name="ID", unique=true, nullable=false, insertable=true, 
updatable=true)
  | 
  |     public int getId() {
  |         return this.id;
  |     }
  |     
  |     public void setId(int id) {
  |         this.id = id;
  |     }
  |     @Column(name="VERSION", unique=false, nullable=false, insertable=true, 
updatable=true)
  | 
  |     public int getVersion() {
  |         return this.version;
  |     }
  |     
  |     public void setVersion(int version) {
  |         this.version = version;
  |     }
  |     @ManyToOne(cascade={},
  |         fetch=FetchType.LAZY)
  |     
  |         @JoinColumn(name="CATEGORY_ID", unique=false, nullable=false, 
insertable=true, updatable=true)
  | 
  |     public Category getCategory() {
  |         return this.category;
  |     }
  |     
  |     public void setCategory(Category category) {
  |         this.category = category;
  |     }
  |     @Column(name="NAME", unique=false, nullable=false, insertable=true, 
updatable=true)
  | 
  |     public String getName() {
  |         return this.name;
  |     }
  |     
  |     public void setName(String name) {
  |         this.name = name;
  |     }
  |     @Column(name="SHOWED", unique=false, nullable=false, insertable=true, 
updatable=true)
  | 
  |     public boolean isShowed() {
  |         return this.showed;
  |     }
  |     
  |     public void setShowed(boolean showed) {
  |         this.showed = showed;
  |     }
  |     @Column(name="PRICE", unique=false, nullable=false, insertable=true, 
updatable=true, precision=12, scale=0)
  | 
  |     public float getPrice() {
  |         return this.price;
  |     }
  |     
  |     public void setPrice(float price) {
  |         this.price = price;
  |     }
  |     @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, 
mappedBy="product")
  | 
  |     public Set<Offer> getOffers() {
  |         return this.offers;
  |     }
  |     
  |     public void setOffers(Set<Offer> offers) {
  |         this.offers = offers;
  |     }
  |     @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, 
mappedBy="product")
  | 
  |     public Set<Billline> getBilllines() {
  |         return this.billlines;
  |     }
  |     
  |     public void setBilllines(Set<Billline> billlines) {
  |         this.billlines = billlines;
  |     }
  |     @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, 
mappedBy="productByProductId")
  | 
  |     public Set<RelatedProducts> getRelatedProductsesForProductId() {
  |         return this.relatedProductsesForProductId;
  |     }
  |     
  |     public void setRelatedProductsesForProductId(Set<RelatedProducts> 
relatedProductsesForProductId) {
  |         this.relatedProductsesForProductId = relatedProductsesForProductId;
  |     }
  |     @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, 
mappedBy="productByRelatedId")
  | 
  |     public Set<RelatedProducts> getRelatedProductsesForRelatedId() {
  |         return this.relatedProductsesForRelatedId;
  |     }
  |     
  |     public void setRelatedProductsesForRelatedId(Set<RelatedProducts> 
relatedProductsesForRelatedId) {
  |         this.relatedProductsesForRelatedId = relatedProductsesForRelatedId;
  |     }
  |     @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, 
mappedBy="product")
  | 
  |     public Set<Entry> getEntries() {
  |         return this.entries;
  |     }
  |     
  |     public void setEntries(Set<Entry> entries) {
  |         this.entries = entries;
  |     }

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

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


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to