We are migrating a legacy application to Hibernate that can dynamically alter tables at runtime to handle custom fields. Can anyone suggest how to extend Hibernate to support persisting these fields? Do we need to extend Hibernate classes (and is there a way to register these extensions?) or would custom EventListeners work somehow?
For example, the CustomPerson table looks like this when no custom fields are defined:
Code:
ID int
LastUpdateTime timestamp
PersonId int (foreign key to Person table)
At runtime, additional columns might be added to store the custom fields
Code:
cf1 varchar
cf2 boolean
etc.
The (simplified) entity class looks like:
Code:
@Entity
@Table(name = "customperson")
public class CustomPerson
{
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer recNum;
@Version @Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateTime;
@OneToOne @JoinColumn(name = "PersonId", unique = true)
private Person person;
@???
private Map<String, Object> customFieldValues;
}
where the customFieldValues map will hold column names and there values for cf1, cf2, etc.
In addition, we need to support multiple databases with different custom tables via a single SessionFactory, so modifying the Configuration with new mappings at runtime (a la
Support of Custom Fields with Hibernate) will not work.
Thanks in advance!
Noah
Hibernate version: 3.3.1
Name and version of the database you are using:MySQL 5.0, SQL Server 2005
Code: