Menu

beanlib3x vs. beanlib5x

Help
Valy Sivec
2008-12-16
2013-04-25
  • Valy Sivec

    Valy Sivec - 2008-12-16

    I'm currently using version 3.x of this library and was wondering if I should switch to v.5.

    Is it too early for this upgrade? Do you plan on maintaining both versions?

    Thanks,
    Valy Sivec

     
    • Joe D. Velopar

      Joe D. Velopar - 2008-12-16

      Definitely worth switching.  The plan is to maintain v5 only in the future.

       
    • sy man

      sy man - 2009-03-11

      I have a Product class and Component class.Product can have Components ie a Set.
      I would like to retrieve a Product from database, change the ids of the Product and associated Components
      and save to database.I am using Hibernate.
      When I do a deepCopy I get an error since the Component's id is sitll being copied on a deep copy.
      Hence, an attempt to write it to database fails.
      This is the pseudocope,any help would be appreciated.

      public class ProductDAOTest extends TestCase {
          //Store to DB
          Product product = new Product("My product");
              product.addComponent(new Component("c1"));
              product.addComponent(new Component("c2"));
              long id = productDAO.store(product);
              hibernateTemplate.flush();
              hibernateTemplate.clear();
             
              //Get from db
              Product retrievedProduct = productDAO.get(id);
             
              ////Replicate
          Product prodCopy =productDAO.deepCopy(retrievedProduct);
              
              /*********  FAILS *********************/
              long idCopy = productDAO.store(prodCopy);
          hibernateTemplate.flush();
              hibernateTemplate.clear();
              
      }
      public class ProductDAO
         {
           public Product deepCopy(Product prodFromDB) {

          Product copy = null;
          try {

          //Override IDs
          HibernatePropertyFilter propertyFilter = new HibernatePropertyFilter() {
                  public boolean propagate(String propertyName,Method readerMethod) {
                      return !"id".equals(propertyName);
                  }
              };

              //Customizing Property handling
              Class<?>[] entityClasses = { Product.class, Component.class };
              Set<Class<?>> entityClassSet = new HashSet<Class<?>>(Arrays.asList(entityClasses));

              //entityclassset,propertiess to be propogate ,veto
              HibernateBeanReplicator replicator = new Hibernate3BeanReplicator(entityClassSet, null, propertyFilter);
              HibernatePropertyFilter propertyFilter2 =replicator.getHibernatePropertyFilter();
              copy = (Product) replicator.deepCopy(prodFromDB);

          } catch (Exception e) {
              e.printStackTrace();
          return copy;
          }
      }

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.