chlabreu wrote:
PS: I'm talking about a Product entity, but this is a generic problem I see in various entities in my application and in many others I can think. When using jdbc+sql, I can simply issue selects and updates against the exact columns I need at each place. But, I think I don't know how to acomplish this with Hibernate in a generic sense and couldn't found detailed explanations about this in docs or faqs.
Yes in JDBC you can naturally have two long-running editors of one database row but editing completely different unrelated columns and the business logic involved is not inter-dependant.
I'm running into little brick walls where a whole bunch of stuff would be really great for the programmer to use Java objects (over JDBC). I would like hibernate to re-use all its knowledge about the mapping of an object to columns to allow for a simple partial row INSERT/UPDATE by primary key.
I would have throught in the core of Hibernate somewhere this already exists, maybe it just needs exposing in a safe way.
I'd then like it to use prepared statements even for partial row operations. I'd like the application to have some control over marking each operation with a caching hint and LRU so the prepared statements cache does not fill up.
MyObject myObject = new MyObject();
myObject.setId(1);
myObject.setMyValue(2);
myObject.setAnotherValue("foobar");
myObject.setThirdValue("three");
myObject.setIgnoredValue("I did not mark this as interesting so hibernate will ignore this bogus value");
HibernateEditOneRecordControlObject eor = new HibernateEditOneRecordControlObject();
eor.addInteredtedColumn("my_value"); // by column name
eor.addInterestedProperty("anotherValue"); // by object property name
eor.addInterestedPropertyNativeSQL("thirdValue", "SERVER_FUNC(?)", "foo");
Session.saveOrUpdate(myObject, eor);
Hibernate then just invalidate any copy of the object it has in cache by that primary key id, the object passed to hibernate would never be attached to the session. Infact this is probably a new object state like "partial" since its not a proper detached object.