views:

73

answers:

1

Can someone please give me some tips on modeling hibernate entities that have some known attributes while the majority are defined by the user of the system (during initial setup of the system)

I need to be able to search on these user defined attributes at a later point in time.

+1  A: 

First of all you'll need to decide on how you're going to model this. Two most common approaches are Entity-Attribute-Value model and row modeling.

The former is (much) easier to deal with using Hibernate; however depending on the search criteria you intend to use it may perform (very) poorly. Certain criteria can not be translated to a single SQL query at all.

The latter is harder to implement as you're looking at both altering your database schema dynamically at runtime and changing Hibernate's configuration to match. Take a look at my answer to How to map dynamically created table in Hibernate for more detail if you choose to go this route.

Another possible alternative is to use Hibernate's support for XML mapping but, again, depending on your search criteria and XML functionality (if any) supported by your underlying database this may or may not be a viable option.

ChssPly76