First, thanks for answering my question.
I don't agree with your idea that generated properties should be managed by application.
Let's read what is mentioned in Hibernate Docs for generated properties:
Quote:
5.6. Generated Properties Generated properties are properties which have their values generated by the database. Typically,
Hibernate applications needed to refresh objects which contain any properties for which the database was generating values. Marking properties as generated, however,
lets the application delegate this responsibility to Hibernate. Essentially, whenever Hibernate issues an SQL INSERT or UPDATE for an entity which has defined generated properties, it immediately issues a select afterwards to retrieve the generated values.
Properties marked as generated must additionally be non-insertable and non-updateable.
http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-generated
So here are my questions:
1. If we have to set the property value (e.g. lastModifiedTime with the method
Code:
setLastModifiedTime(Date date)
), what is the use of hibernate feature 'generated properties'.
2. The doc says that: "lets the application delegate this responsibility to Hibernate". This means, Hibernate should assign the value to the property marked as generated before the SQL is issued. Why this is not happening?
3. I have seen that hibernate is issuing a SELECT statement after INSERT/UPDATE for the entity with generated property. But some how it is not assigning any value to the property marked as generated.
4. Inside the mapping for generated property, we have
Code:
insert="false", update="false"
, in that case what is the use of setting the value for property, i.e. lastModifiedTime when it is not part of INSERT/UPDATE statement.
5. Finally, I think hibernate should manage setting the value for 'generated' properties - from Hibernate side or by creating and attaching a trigger (or what ever suitable SQL event for that dialect). So it is not responsibility of the application to assign values for generated properties.
Thanks
Shyam