-
Notifications
You must be signed in to change notification settings - Fork 0
Dynamic EntityTypes
Stefan Meyer edited this page Jul 28, 2012
·
3 revisions
Types can also be created programmatically. This makes sense if the type is not defined by a java class or other means of static type definition like a schema (xml, json, rdbms, ..).
DynamicEntityTypes can be defined at runtime by using an EntityTypeBuilder. It offers ways to add attributes of various types. The concrete implementation will throw an UnsupportedOperationException if you specify attributes that it doesn't support (e.g.: json only supports a limited set of primitive types and only ordered collections).
An EntityTypeBuilder can be created by an instanceof DynamicEntityTypeSubrepository.
@Resource
DynamicEntityTypeSubrepository<?> jsonRepository;
EntityType<?> createType() {
Type<?> intType = entityTypeRepository.getType(Integer.class);
EntityTypeBuilder jsonTypeBuilder = jsonRepository.createBuilder("nameOfMyType");
jsonTypeBuilder.addSingleAttribute("totalAmount",intType);
return jsonTypeBuilder.createEntityType();
}