I'll dive right into a simple example to explain my question:
Code:
table log_entry(id, level, msg)
table log_level(id, name)
log_entry.level references log_level.id
a unique constraint on log_level.name
Code:
select * from log_level
1, ERROR
2, INFO
3, DEBUG
("ERROR" etc. acts here as a natural id, such that the row of log_level is identified in a unique way)
Now for the Hibernate Mapping for the log_entry:
I could just introduce a property for the level, which would yield something like a setLevel(int) method, by simply setting the foreign key.
Or I could use a many-to-one mapping, that would result in a setLevel(LogLevel) method, but this way I would have to use a LogLevel object.
But is it possible to create a mapping for the log_entry, such that you cat set the log level of a log entry by using e.g. setLevel("ERROR")?
I've looked into several mapping chapters but have not found anything with which I could realize the mapping above. Is it possible to realize with Hibernat at all?
Code: