snippetjournal

- notes, snippet codes, and my journal

Hibernate : Understanding First level and Second level cache

leave a comment »

really good and easy to understanding tutorial :)

note :

  • SessionFactory provides session, session maintains cache.
  • How will session cache object get update from DB if any changes happen. Will get update automatically or explicitily.?

In case of single session, your application code always update this cache object so it is always updated. Hibernate takes care of synchronizing the changes with database at time of flushing the session.

Now consider another example:

machine 1: reads the data and returns it for editing somewhere else
machine 2: also reads the data for modification
machine 1: updates the data and commits.
machine 2: tries to do an update and commit.

What will happen when the second machine tries to commit its changes? Hibernate will see that the data has changed while machine 2 was working on the data. That is, machine 2’s update is on stale data. Hibernate can’t always merge the two changes (nor is that always desired behaviour), so it rejects the second update by throwing org.hibernate.StaleObjectStateException.

The simplest solution, perhaps, is to add a version field using @Version on your data objects. Hibernate will automatically maintain the “version” of the data. Whenever an update takes place, the version will be changed automatically by Hibernate. Your job is the check that the version hasn’t changed between when you read the data and when you update the data. If they don’t match, you can do something to handle the problem (i.e. tell the user). There are some more sophisticated techniques for preventing concurrent updates, but this is the simplest.

Written by snippetjournal

November 24, 2014 at 3:33 am

Posted in Uncategorized

Sonatypes Maven References

leave a comment »

Written by snippetjournal

November 20, 2014 at 2:47 am

Posted in Uncategorized

SVN: trunk, branch and tag, explanation

leave a comment »

Written by snippetjournal

November 20, 2014 at 2:34 am

Posted in Uncategorized

IVY Tutorial

leave a comment »

I found this was a great tutorial about ivy, credits to the author

Written by snippetjournal

November 18, 2014 at 3:33 am

Posted in Uncategorized

Send Multipart/Attachment email Using MimeMessageHelper

leave a comment »

Berikut ini penjelasan singkat dari penggunaan javaMailSender yang saya implementasikan pada project. Dengan menggunakan velocity template kita dapat menggunakan template html dengan mudah pada class email sender kita.

anda bisa menggunakan beberapa template email yang bertebaran di internet, saya sendiri mengambil template email dari zurb.com.

pada contoh kedua link di atas menurut saya implementasi kode ketika akan mengirim email cukup banyak boilerplate codes yang digunakan. sehingga saya mencoba untuk membungkus code tersebut nya agar lebih mudah penggunaannya dan menghindari menggunakan code secara berulang ulang.

  • Pertama buat class , class ini hanya berfungsi sebagai penampung dari attribute attribute yang diperlukan pada java mail sender.
  • Kemudian buat class class ini berperan sebagai class yang ditujukan untuk mengirim email. autowired object javaMailSender dan velocityEngine agar bisa kita gunakan untuk mengirim email.
  • Yang perlu diperhatikan adalah ketika kita akan membuat email yang di sertakan email attachment maka constructor MimeMessageHelper harus di buat TRUE, new MimeMessageHelper(mm, true);

setelah class class tadi sudah di buat maka cara penggunaan javaSender pun akan berubah, berikut cara nya jangan lupa untuk autowired class emailSender.

  • yang perlu diperhatikan, saya mengubah object String menjadi file yang akan di attachment.
  • emailErrorLogs.vm adalah template html yang akan di tampilkan pada email. cukup ubah ekstensi html menjadi vm

Written by snippetjournal

October 17, 2014 at 2:16 pm

AJAX Tutorial

leave a comment »

Written by snippetjournal

October 16, 2014 at 1:56 pm

Posted in Uncategorized

Spark

leave a comment »

Apache Spark is a fast and general-purpose cluster computing system. It provides high-level APIs in Java, Scala and Python, and an optimized engine that supports general execution graphs. It also supports a rich set of higher-level tools including Spark SQL for SQL and structured data processing, MLlib for machine learning, GraphX for graph processing, and Spark Streaming.

Written by snippetjournal

October 16, 2014 at 2:00 am

Posted in Uncategorized

Follow

Get every new post delivered to your Inbox.

Join 67 other followers