Παρασκευή 17 Οκτωβρίου 2014

Gradle for Java, Eclipse and Spring

This article explains the first steps in getting familiar with Gradle for use with Eclipse IDE and Spring Framework. Gradle is a build automation tool combining the benefits of Ant and Maven developing tools.

As I would rather install minimum in my computer I am not going to install Gradle but I would rather use the Eclipse Integration Gradle plug-in. This is easily installed following the below instructions:

1. At the top of the Eclipse window, select “Help” -> “Install New Software”.
2. In the “Install New Software” dialog, click the “Add” button to add a new software site.
3. Enter any name for the repository it doesn’t really matter what you choose.
4. Enter the url of the Eclipse Integration Gradle plug-in: http://dist.springsource.com/release/TOOLS/gradle
5. Select the Gradle repository from the repository list.
6. Check the box next to “Extensions / Gradle Integration” -> “Gradle IDE”.
7. Hit “Next” twice, then accept the license agreement and click “Finish”.

To open a Gradle project in Eclipse you do as follows:

1. Open Eclipse. Select “File”->”Import”.
2. Select “Gradle Project”, under “Gradle”.
3. Locate the project. The project folder should contain a file called “build.gradle”. However this file may or may not show up in Eclipse’s filesystem browser.
4. Click “Build Model”, then check the box next to the project that should appear and click “Finish”.

Some Hibernate - JPA Notes

1) What does cascade = CascadeType.ALL mean?

CascadeType.ALL means it will do all following actions:
CascadeType.PERSIST: When persisting an entity, also persist the entities held in this field. We suggest liberal application of this cascade rule, because if the EntityManager finds a field that references a new entity during flush, and the field does not use CascadeType.PERSIST, it is an error.
CascadeType.REMOVE: When deleting an entity, also delete the entities held in this field.
CascadeType.REFRESH: When refreshing an entity, also refresh the entities held in this field.
CascadeType.MERGE: When merging entity state, also merge the entities held in this field.

2) JPA 2.0 is blocking to nest a @ElementCollection inside a @Embeddable defined in another @ElementCollection:

JSR-317 2.6 Collections of Embeddable Classes and Basic Types An embeddable class (including an embeddable class within another embeddable class) that is contained within an element collection must not contain an element collection, nor may it contain a relationship to an entity other than a many-to-one or one-to-one relationship.

3) Batch Save with Hibernate

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000 data-blogger-escaped-customer="" data-blogger-escaped-i="" data-blogger-escaped-pre="" data-blogger-escaped-session.close="" data-blogger-escaped-session.save="" data-blogger-escaped-tx.commit="">


Load LAZY.fetch attributes

Use this command Hibernate.initialize(company.getTurnovers());