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

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());

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου