CHAPTER 3 Domain models and metadata Long storedItemId (Web hosting domains)

CHAPTER 3 Domain models and metadata Long storedItemId = (Long) item1.get(”id”); Session session = getSessionFactory().openSession(); session.beginTransaction(); Map loadedItemMap = (Map) session.load(”ItemEntity”, storedItemId); loadedItemMap.put(”initialPrice”, new BigDecimal(100)); session.getTransaction().commit(); session.close(); All Session methods that have class parameters such as load() also come in an overloaded variation that accepts entity names. After loading an item map, you set a new price and make the modification persistent by committing the transaction, which, by default, triggers dirty checking and flushing of the Session. You can also refer to entity names in HQL queries: List queriedItemMaps = session.createQuery(”from ItemEntity where initialPrice >= :p”) .setParameter(”p”, new BigDecimal(100)) .list(); This query returns a collection of ItemEntity maps. They are in persistent state. Let s take this one step further and mix a POJO model with dynamic maps. There are two reasons why you would want to mix a static implementation of your domain model with a dynamic map representation: You want to work with a static model based on POJO classes by default, but sometimes you want to represent data easily as maps of maps. This can be particularly useful in reporting, or whenever you have to implement a generic user interface that can represent various entities dynamically. You want to map a single POJO class of your model to several tables and then select the table at runtime by specifying a logical entity name. You may find other use cases for mixed entity modes, but they re so rare that we want to focus on the most obvious. First, therefore, you ll mix a static POJO model and enable dynamic map representation for some of the entities, some of the time. Mixing dynamic and static entity modes To enable a mixed model representation, edit your XML mapping metadata and declare a POJO class name and a logical entity name: We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.