CHAPTER 3 Domain models and metadata
There are three interesting things to observe in this mapping file. First, you mix several class mappings in one, something we didn t recommend earlier. This time you aren t really mapping Java classes, but logical names of entities. You don t have a Java source file and an XML mapping file with the same name next to each other, so you re free to organize your metadata in any way you like. Second, the attribute has been replaced with . You also append …Entity to these logical names for clarity and to distinguish them from other nondynamic mappings that you made earlier with regular POJOs. Finally, all entity associations, such as and , now also refer to logical entity names. The class attribute in the association mappings is now entity-name. This isn t strictly necessary Hibernate can recognize that you re referring to a logical entity name even if you use the class attribute. However, it avoids confusion when you later mix several representations. Let s see what working with dynamic entities looks like. Working with dynamic maps To create an instance of one of your entities, you set all attribute values in a Java Map: Map user = new HashMap(); user.put(”username”, “johndoe”); Map item1 = new HashMap(); item1.put(”description”, “An item for auction”); item1.put(”initialPrice”, new BigDecimal(99)); item1.put(”seller”, user);
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.
This entry was posted
on Monday, November 26th, 2007 at 1:25 am and is filed under PHP5.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.