-
1. Re: EntityHome.find after persist entity
valatharv Oct 3, 2008 4:55 PM (in response to greatjapa)Hi Marcelo,
Did you found any solution I need to make JDBC call immediately AFTER persist to insert a row in some table.
Is there any mothod which I can override... or any other option...
-
2. Re: EntityHome.find after persist entity
andygibson.contact.andygibson.net Oct 3, 2008 10:04 PM (in response to greatjapa)One of two options.
Find will just re-use the instance the the entity manager already has locally without going back to the database. You probably want to call entityManager.refresh(getInstance()) in the entity home instead.
Alternatively, if the property is immutable, I think you can use the @Generated hibernate annotation which will mark the property as immutable and also perform an automatic refresh which it is persisted.
Cheers,
Andy Gibson
-
3. Re: EntityHome.find after persist entity
valatharv Oct 3, 2008 10:37 PM (in response to greatjapa)Thanks for replying Andy...
I just need to call a function "insertQuantReagent();", once the values are commited to database.
Will entityManager.refresh(getInstance()) commit the database before calling my function... which will be the best place to add it...
@Override
public String persist(){
getReagent();
String persistResult = super.persist();
insertQuantReagent();//<--- CALLING IT
return persistResult;
}
public void insertQuantReagent(){
Utils u = new Utils();
try {
u.insertIntoQauntExpReagentJoinTable(1,instance.getHjid());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// But this should be called after persist() method
} -
4. Re: EntityHome.find after persist entity
andygibson.contact.andygibson.net Oct 4, 2008 5:07 AM (in response to greatjapa)Do you really only want to insert the rows if the item has been commited, or just when it has been fliushed to the database and not committed? What if your insert fails and you have the entity committed but without the additional reagent inserted?
The persist method will flush it to the database, but it won't commit until the method has finished. However flushing is good enough as it makes it queryable since it is all taking place within the same transaction.
In the code you wrote, I believe the two inserts will take place in the same transaction, and will both commit or rollback together.
If this is related to your other post with one to one and one to many mappings, you can let JPA handle all that with the right relational mappings and cascades defined.
Cheers,
Andy