[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3317?page=c...
]
Martin Backhaus commented on HHH-3317:
--------------------------------------
I don't want to close this issue.
In my opinion this is a massive bug, because every developer, who trust Hibernate, will
get in trouble with such differences in behavior of the Hibernate-Event-System.
If this behavior is expected (as said in HHH-1241) then should be a Exception thrown, when
inserting an entity within onFlush() - or write a log-message to give the developer a
chance.
Here my workaround for pitiful Oracle-Users :
public boolean onPreUpdate(final PreUpdateEvent arg0)
{
...
saveInSubSession(myEntity, arg0.getSource());
...
}
/**
* WORKAROUND for saving something in Oracle within an event
* @see
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3317
*/
private void saveInSubSession(final Object entity, final SessionImplementor si)
{
final Session sessionForSaving =
si.getFactory().openSession(si.getJDBCContext().connection());
sessionForSaving.save(entity);
// If you do something within onFlush() -> be sure to save things which would be
changed
sessionForSaving.flush();
// If you do something within onFlush() -> be sure to revert it at this point
}
Entities saved within onPreUpdate() never inserted into db when id
generator is sequenze (f.e. oracle)
------------------------------------------------------------------------------------------------------
Key: HHH-3317
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3317
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.6
Environment: hibernate3.2.6.ga.jar, Oracle 10
Reporter: Martin Backhaus
Priority: Minor
Attachments: HHH_3317.hbm.xml, HHH_3317_Test.java
If you save (insert) a entity within the event preUpdate and the id is a oracle-sequenze,
hibernate put the entity to insert in the session-ActionQueue, BUT NEVER INSERTS it. If
you use mysql/hsql... where the id is differently generated, the insert happens
immediately and no put to the ActionQueue occures.
As workaround you can queue the object (to insert) yourself and call save() within the
postUpdate-Event.
I use this events for historizing some stuff.
Inserts within onDelete() works fine.
the ids are annotated as shown here:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id = null;
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira