Hi,
I am about to start writing my master's project and I have first solid dilema.
I have a choice
1. create as normalized db as it is possible, using multiple primary keys and complitated hibernate composite keys. The advantage - well designed database.
2. create java classes extending base model with hibernate.id and set it as primary key in each table, even many-to-many junction tables (or maybe here i could make an exception). The disadvantage - not good database - i.e. class:
Worker
hibernate.id id
personalID - unique personal data, one in the country for one person,
otherNumber - unique personal data, one in the country for one person,
I NEED TO HAVE TWO fields which normally would be primary keys - if I had only personalID, my problem would be simple resolved - put unique constraint to avoid data repetition. But there will be tables with >=2 id fields apart from hibernate.id (third one). To the bes of my knowledge I can't set composite unique constraints on a table. in POSTGRE SQL 8
then i would have possibility to put into my db the same worker many times, which is an error. Nex disadventage would be that befor insert of such a worker i would hav to check in my code if he hasn't been already inserted.
But i've found in your tutorial
http://www.hibernate.org/hib_docs/v3/re ... rial-intro :
Quote:
The id property holds a unique identifier value for a particular event. All persistent entity classes (there are less important dependent classes as well) will need such an identifier property if we want to use the full feature set of Hibernate. In fact, most applications (esp. web applications) need to distinguish objects by identifier, so you should consider this a feature rather than a limitation. However, we usually don't manipulate the identity of an object, hence the setter method should be private. Only Hibernate will assign identifiers when an object is saved. You can see that Hibernate can access public, private, and protected accessor methods, as well as (public, private, protected) fields directly. The choice is up to you and you can match it to fit your application design.
So could u please tell me why should I follow it? I am not experienced enough to outnumber the disadvantages that i've mentioned.
Could u point them to me so that i could use these hints in my project ?
I have to justify resigning from normilized db and putting some objectId in each table just for hibernate..
I also want to use HibernateTemplate :
protected BaseModel readModel(Class clazz, Long id) {
return (BaseModel) getHibernateTemplate().load(clazz,id);
}
but I could always make a select query.