Making data persistent in android

Many applications may provide a way to capture user preferences on the settings of a specific application or an activity. For supporting this, Android provides a simple set of APIs. Preferences are typically name value pairs. They can be stored as “Shared Preferences” across various activities in an application (note currently it cannot be shared … Read more

Persistence unit as RESOURCE_LOCAL or JTA?

JPA implementations have the choice of managing transactions themselves (RESOURCE_LOCAL), or having them managed by the application server’s JTA implementation. In most cases, RESOURCE_LOCAL is fine. This would use basic JDBC-level transactions. The downside is that the transaction is local to the JPA persistence unit, so if you want a transaction that spans multiple persistence … Read more

When to use EntityManager.find() vs EntityManager.getReference() with JPA

I usually use getReference method when i do not need to access database state (I mean getter method). Just to change state (I mean setter method). As you should know, getReference returns a proxy object which uses a powerful feature called automatic dirty checking. Suppose the following public class Person { private String name; private … Read more

Solve Hibernate Lazy-Init issue with hibernate.enable_lazy_load_no_trans

The problem with this approach is that you can have the N+1 effect. Imagine that you have the following entity: public class Person{ @OneToMany // default to lazy private List<Order> orderList; } If you have a report that returns 10K of persons, and if in this report you execute the code person.getOrderList() the JPA/Hibernate will … Read more

How persistent is localStorage?

Mozilla implements it like cookies: DOM Storage can be cleared via “Tools -> Clear Recent History -> Cookies” when Time range is “Everything” (via nsICookieManager::removeAll) https://developer.mozilla.org/en/DOM/Storage In DOM Storage it is not possible to specify an expiration period for any of your data. All expiration rules are left up to the user. In the case … Read more

Confusion: @NotNull vs. @Column(nullable = false) with JPA and Hibernate

@NotNull is a JSR 303 Bean Validation annotation. It has nothing to do with database constraints itself. As Hibernate is the reference implementation of JSR 303, however, it intelligently picks up on these constraints and translates them into database constraints for you, so you get two for the price of one. @Column(nullable = false) is … Read more

No Persistence provider for EntityManager named

Put the “hibernate-entitymanager.jar” in the classpath of application. For newer versions, you should use “hibernate-core.jar” instead of the deprecated hibernate-entitymanager If you are running through some IDE, like Eclipse: Project Properties -> Java Build Path -> Libraries. Otherwise put it in the /lib of your application.

Saving an Object (Data persistence)

You could use the pickle module in the standard library. Here’s an elementary application of it to your example: import pickle class Company(object): def __init__(self, name, value): self.name = name self.value = value with open(‘company_data.pkl’, ‘wb’) as outp: company1 = Company(‘banana’, 40) pickle.dump(company1, outp, pickle.HIGHEST_PROTOCOL) company2 = Company(‘spam’, 42) pickle.dump(company2, outp, pickle.HIGHEST_PROTOCOL) del company1 del … Read more