Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
22. Aug 2008, 22:22 CET | Link

I have an EntityHome class called Subscription. This Home has two methods: method-A and method-B. The method-A persists an entity and before returning the persisted String I call the method-B. Inside method-B I need to load the instance again because some fields are filled by one database trigger, but when I try to load the instance, the Home (using find method) did not execute a search and can't get the values filled by the trigger.

Someone has any idea of what is happening?

Does anyone know how can I solve this?

4 Replies:
03. Oct 2008, 16:55 CET | Link
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...

03. Oct 2008, 22:04 CET | Link

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

 

It's a job that's never started that takes the longest to finish. - J.R.R. Tolkien

---------- www.andygibson.net ----------

03. Oct 2008, 22:37 CET | Link
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
   }
04. Oct 2008, 05:07 CET | Link

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

 

It's a job that's never started that takes the longest to finish. - J.R.R. Tolkien

---------- www.andygibson.net ----------