Hibernate - flush e Transaction

Alguém poderia me explicar a diferença entre o flush() e o transaction().

Esta lendo um tutorial e não consegui distinguir a diferenã entre eles.

Apenas sei que o fush() obriga a inserção do dados a partir de um buffer (me corrijam se estiver errado), e o transaction eu não entendi direito.

Utiliza-se após criar uma sessão, salvar e depois? utiliza qual?

obrigado e desculpas se foi uma “pergunta idiota”.

Bom dia!!!

Segue o link da API do Hibernate…

https://www.hibernate.org/hib_docs/v3/api/org/hibernate/Transaction.html

Até mais…

acho que a sua duvida na verdade é entre o commit()e o flush(), certo?
Nunca entendi a diferença tb… alguem saberia explicar?

Achei uma explicação q ajudou um pouco:

[quote]The difference between flush and commit are :

  • Commit will make the database commit
  • Flushing is the process of synchronizing the underlying persistent
    store with persistable state held in memory.
    ie. it will update or insert into your tables in the running
    transaction, but it may not commit those changes (this depends on
    your flush mode). When you have a persisted object and you change a
    value on it, it becomes dirty and hibernate needs to flush these
    changes to your persistence layer. It may do this automatically for
    you or you may need to do this manually, that depends on your flush
    mode, check http://www.hibernate.org/hib_docs/v3/api/org/hibernate/FlushMode.html
    for further details on which flush mode is the right one for you.[/quote]

É mais ou menos…

Assim, tenho dúvidas também onde eu vou inserir os comandos…

Primeiro vem o flush() depois o commit()?

precisa-se realmente usar o flush (pra garantir a retidada dos arquivos do buffer)? e depois persistir…??

Qual seria os melhores procedimentos para inserir os dados no banco…

Porque usar o Transaction?