[Hibernate] Refresh After saveOrUpdate
Hibernate version: 3.0.5 In the Hibernate application that we're working on, we've got a generic saveObject method in one of our DAOs. The intent of this method is to insert the object if it is transient or update it if it is detached. The database we're using has a set of triggers that execute before inserts and updates that set some auditing fields such as created_date and modified_date. Since these fields are set by a trigger, Hibernate doesn't know that they've been modified and the updated values are not populated/updated in my objects. I would like for the saveObject method to reload the data from the database after inserts/updates so that these values show up in the objects that we're saved. public void saveObject(final Object object) { getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { session.saveOrUpdate(object); session.flush(); session.refresh(object); return null; } }); } The idea is that a flush is forced after the save, and then a call to refresh forces Hibernate to reload the object's state from the database. This code works fine for persistent objects. However, for transient objects that need to be inserted, I'm getting an UnresolvableObjectException on the call to session.refresh(object). This led me to believe that the insert wasn't happening, but I've enabled P6Spy and verified that there is a SQL INSERT statement, followed by a SQL SELECT (some fields masked): 1118933686257|10|0|statement|insert into STATUS (NAME, CREATED_BY, MODIFIED_BY, STATUS_ID) values (?, ?, ?, ?)|insert into STATUS (NAME, CREATED_BY, MODIFIED_BY, STATUS_ID) values ('Insert Test', '***', '***', 292) 1118933686267|10|0|statement|select status0_.STATUS_ID as STATUS1_0_, status0_.NAME as NAME35_0_, status0_.CREATED_DATE as CREATED3_35_0_, status0_.CREATED_BY as CREATED4_35_0_, status0_.MODIFIED_BY as MODIFIED5_35_0_, status0_.MODIFIED_DATE as MODIFIED6_35_0_ from STATUS status0_ where status0_.STATUS_ID=?|select status0_.STATUS_ID as STATUS1_0_, status0_.NAME as NAME35_0_, status0_.CREATED_DATE as CREATED3_35_0_, status0_.CREATED_BY as CREATED4_35_0_, status0_.MODIFIED_BY as MODIFIED5_35_0_, status0_.MODIFIED_DATE as MODIFIED6_35_0_ from STATUS status0_ where status0_.STATUS_ID=292 Note that we're using Spring's support for declarative transactions, and the transactionAttributes relevant to this method are: prop key=save*PROPAGATION_REQUIRED/prop Does anyone have any insight into this problem? The relevant portion of the exception stack trace is below: org.hibernate.UnresolvableObjectException: No row with the given identifier exists: [com.fmr.eaccess.domain.eaccess.Status#298] at org.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:42) at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:105) at org.hibernate.impl.SessionImpl.refresh(SessionImpl.java:679) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1004) at $Proxy2.refresh(Unknown Source) at com.fmr.eaccess.dao.hibernate.HibernateSystemAdminDao$2.doInHibernate(HibernateSystemAdminDao.java:109) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:288) at com.fmr.eaccess.dao.hibernate.HibernateSystemAdminDao.saveObject(HibernateSystemAdminDao.java:92) at com.fmr.eaccess.service.SystemAdminServiceImpl.saveObject(SystemAdminServiceImpl.java:71) -- Jason Voegele There is an essential core at the center of each man and woman that remains unaltered no matter how life's externals may be transformed or recombined. But it's smaller than we think. -- Gene Wolfe, The Book of the Long Sun --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
RE: [Hibernate] Field interception based proxies
Juozas, I don't really understand what you are proposing here. What is a field interception based proxy? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of baliuka juozas Sent: Wednesday, 29 June 2005 9:30 AM To: hibernate-devel@lists.sourceforge.net Subject: [Hibernate] Field interception based proxies Hi, I am going to implement field interception based proxies, I will need this stuff for projects with many classes (I see it can be implemnted using custom persister), probably it makes sence to add this feature for hibernate too if this is interesting for hibernate community. Implemetation must be trivial, but there is single problem with id field name. I can asume this field name is always id, but if we are going to make this stuff public then we need to find better way. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77alloc_id492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] Refresh After saveOrUpdate
On Jun 30, 2005, at 7:02 PM, Jason Voegele wrote: Does anyone have any insight into this problem? Why do you think the developer mailing list is the right place to ask usage questions when everything on our website tells you not to do so? --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
RE: [Hibernate] Field interception based proxies
I think it must be usefull to avoid proxy generation if persistent class implements HibernateProxy itself. I am going to implement it at build time using field interceptor ( it will take less time on startup and it will use less permanent memory ). It is not a proxy, but it will work in the same way from user point of view ( without changes in mapping files, just an heuristic optimization ). As I understand it needs trivial changes in proxy factory, but it makes sence with many domain classes. --- Gavin King [EMAIL PROTECTED] wrote: Juozas, I don't really understand what you are proposing here. What is a field interception based proxy? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of baliuka juozas Sent: Wednesday, 29 June 2005 9:30 AM To: hibernate-devel@lists.sourceforge.net Subject: [Hibernate] Field interception based proxies Hi, I am going to implement field interception based proxies, I will need this stuff for projects with many classes (I see it can be implemnted using custom persister), probably it makes sence to add this feature for hibernate too if this is interesting for hibernate community. Implemetation must be trivial, but there is single problem with id field name. I can asume this field name is always id, but if we are going to make this stuff public then we need to find better way. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77alloc_id492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
RE: [Hibernate] Field interception based proxies
Will it work with polymorphic -to-one associations? You still need the indirection in that case, don't you? -Original Message- From: baliuka juozas [mailto:[EMAIL PROTECTED] Sent: Thursday, 30 June 2005 11:37 AM To: Gavin King; hibernate-devel@lists.sourceforge.net Subject: RE: [Hibernate] Field interception based proxies I think it must be usefull to avoid proxy generation if persistent class implements HibernateProxy itself. I am going to implement it at build time using field interceptor ( it will take less time on startup and it will use less permanent memory ). It is not a proxy, but it will work in the same way from user point of view ( without changes in mapping files, just an heuristic optimization ). As I understand it needs trivial changes in proxy factory, but it makes sence with many domain classes. --- Gavin King [EMAIL PROTECTED] wrote: Juozas, I don't really understand what you are proposing here. What is a field interception based proxy? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of baliuka juozas Sent: Wednesday, 29 June 2005 9:30 AM To: hibernate-devel@lists.sourceforge.net Subject: [Hibernate] Field interception based proxies Hi, I am going to implement field interception based proxies, I will need this stuff for projects with many classes (I see it can be implemnted using custom persister), probably it makes sence to add this feature for hibernate too if this is interesting for hibernate community. Implemetation must be trivial, but there is single problem with id field name. I can asume this field name is always id, but if we are going to make this stuff public then we need to find better way. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77alloc_id492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77alloc_id492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] Refresh After saveOrUpdate
On Thu, June 30, 2005 1:25 pm, Christian Bauer said: On Jun 30, 2005, at 7:02 PM, Jason Voegele wrote: Does anyone have any insight into this problem? Why do you think the developer mailing list is the right place to ask usage questions when everything on our website tells you not to do so? My apologies. I did post this to the Hibernate forum first but got no response after more than a week. I also thought that this might possibly be a bug, since I'm using the refresh() method exactly as specified in the Hibernate documentation and book, in which case I felt that the developers mailing list would be an appropriate place. Sorry. -- Jason Voegele There is an essential core at the center of each man and woman that remains unaltered no matter how life's externals may be transformed or recombined. But it's smaller than we think. -- Gene Wolfe, The Book of the Long Sun --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
RE: [Hibernate] Field interception based proxies
I see no good way to make it lazy and to create the right type for polymorphic associations, if I understand the problem correctly then we need to know discriminator value before to create instance anyway. --- Gavin King [EMAIL PROTECTED] wrote: Will it work with polymorphic -to-one associations? You still need the indirection in that case, don't you? -Original Message- From: baliuka juozas [mailto:[EMAIL PROTECTED] Sent: Thursday, 30 June 2005 11:37 AM To: Gavin King; hibernate-devel@lists.sourceforge.net Subject: RE: [Hibernate] Field interception based proxies I think it must be usefull to avoid proxy generation if persistent class implements HibernateProxy itself. I am going to implement it at build time using field interceptor ( it will take less time on startup and it will use less permanent memory ). It is not a proxy, but it will work in the same way from user point of view ( without changes in mapping files, just an heuristic optimization ). As I understand it needs trivial changes in proxy factory, but it makes sence with many domain classes. --- Gavin King [EMAIL PROTECTED] wrote: Juozas, I don't really understand what you are proposing here. What is a field interception based proxy? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of baliuka juozas Sent: Wednesday, 29 June 2005 9:30 AM To: hibernate-devel@lists.sourceforge.net Subject: [Hibernate] Field interception based proxies Hi, I am going to implement field interception based proxies, I will need this stuff for projects with many classes (I see it can be implemnted using custom persister), probably it makes sence to add this feature for hibernate too if this is interesting for hibernate community. Implemetation must be trivial, but there is single problem with id field name. I can asume this field name is always id, but if we are going to make this stuff public then we need to find better way. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77alloc_id492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com __ Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
RE: [Hibernate] Field interception based proxies
Yes, exactly. -Original Message- From: baliuka juozas [mailto:[EMAIL PROTECTED] Sent: Thursday, 30 June 2005 1:22 PM To: Gavin King; hibernate-devel@lists.sourceforge.net Subject: RE: [Hibernate] Field interception based proxies I see no good way to make it lazy and to create the right type for polymorphic associations, if I understand the problem correctly then we need to know discriminator value before to create instance anyway. --- Gavin King [EMAIL PROTECTED] wrote: Will it work with polymorphic -to-one associations? You still need the indirection in that case, don't you? -Original Message- From: baliuka juozas [mailto:[EMAIL PROTECTED] Sent: Thursday, 30 June 2005 11:37 AM To: Gavin King; hibernate-devel@lists.sourceforge.net Subject: RE: [Hibernate] Field interception based proxies I think it must be usefull to avoid proxy generation if persistent class implements HibernateProxy itself. I am going to implement it at build time using field interceptor ( it will take less time on startup and it will use less permanent memory ). It is not a proxy, but it will work in the same way from user point of view ( without changes in mapping files, just an heuristic optimization ). As I understand it needs trivial changes in proxy factory, but it makes sence with many domain classes. --- Gavin King [EMAIL PROTECTED] wrote: Juozas, I don't really understand what you are proposing here. What is a field interception based proxy? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of baliuka juozas Sent: Wednesday, 29 June 2005 9:30 AM To: hibernate-devel@lists.sourceforge.net Subject: [Hibernate] Field interception based proxies Hi, I am going to implement field interception based proxies, I will need this stuff for projects with many classes (I see it can be implemnted using custom persister), probably it makes sence to add this feature for hibernate too if this is interesting for hibernate community. Implemetation must be trivial, but there is single problem with id field name. I can asume this field name is always id, but if we are going to make this stuff public then we need to find better way. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77alloc_id492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com __ Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77alloc_id492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
RE: [Hibernate] Field interception based proxies
Probably single workaround is public cast or narrow method in API, we can load object if it is not loaded and to remove proxy from session cache. --- Gavin King [EMAIL PROTECTED] wrote: Yes, exactly. -Original Message- From: baliuka juozas [mailto:[EMAIL PROTECTED] Sent: Thursday, 30 June 2005 1:22 PM To: Gavin King; hibernate-devel@lists.sourceforge.net Subject: RE: [Hibernate] Field interception based proxies I see no good way to make it lazy and to create the right type for polymorphic associations, if I understand the problem correctly then we need to know discriminator value before to create instance anyway. --- Gavin King [EMAIL PROTECTED] wrote: Will it work with polymorphic -to-one associations? You still need the indirection in that case, don't you? -Original Message- From: baliuka juozas [mailto:[EMAIL PROTECTED] Sent: Thursday, 30 June 2005 11:37 AM To: Gavin King; hibernate-devel@lists.sourceforge.net Subject: RE: [Hibernate] Field interception based proxies I think it must be usefull to avoid proxy generation if persistent class implements HibernateProxy itself. I am going to implement it at build time using field interceptor ( it will take less time on startup and it will use less permanent memory ). It is not a proxy, but it will work in the same way from user point of view ( without changes in mapping files, just an heuristic optimization ). As I understand it needs trivial changes in proxy factory, but it makes sence with many domain classes. --- Gavin King [EMAIL PROTECTED] wrote: Juozas, I don't really understand what you are proposing here. What is a field interception based proxy? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of baliuka juozas Sent: Wednesday, 29 June 2005 9:30 AM To: hibernate-devel@lists.sourceforge.net Subject: [Hibernate] Field interception based proxies Hi, I am going to implement field interception based proxies, I will need this stuff for projects with many classes (I see it can be implemnted using custom persister), probably it makes sence to add this feature for hibernate too if this is interesting for hibernate community. Implemetation must be trivial, but there is single problem with id field name. I can asume this field name is always id, but if we are going to make this stuff public then we need to find better way. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477alloc_id=16492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77alloc_id492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com __ Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html --- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77alloc_id492op=click ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com