Base Entity Classes

From Opentaps Wiki
Revision as of 22:54, 13 August 2008 by Sichen (talk | contribs) (Protected "Base Entity Classes": Sysop page [edit=sysop:move=sysop])
Jump to navigationJump to search

To support the object-oriented Domain Driven Architecture, there is a set of Java entity classes in the org.opentaps.domain.base.entities package for all the entities defined with the ofbiz entity engine, both from the original ofbiz applications and the opentaps applications. The entity classes contain all the fields of the entity, accessor (get/set) methods for each field, and fromMap and toMap methods to convert the Java class to a Map.

The entity classes are automatically generated using a freemarker template hot-deploy/opentaps-common/templates/BaseEntity.ftl, based on the entitymodel.xml definitions for all the entities, including view-entities and fields defined by the extend-entity tags, and the Java types defined in the fieldtype XML files for the entity engine. To generate base entities, from the opentaps directory,

$ ant make-base-entities

It will clear out all the files in the base entities package, start opentaps and load the delegator, and then regenerate the Java classes based on the current entity definitions.

The base entity Java classes could be used as a replacement for the ofbiz GenericEntity/GenericValue objects. To go from a GenericValue to a Java class, use the Repository.loadFromGeneric methods, such as:


These methods uses reflection to access the fromMap method of entity classes.

To go from a Java class, you can simply use the toMap method to create a GenericValue, such as:


DO NOT MODIFY THESE BASE ENTITY CLASSES. They should be automatically generated every time your data model changes, so all your changes will be overwritten. If you have more complex classes, extend these base entity classes and implement the additional methods there.