Avoid Jackson serialization on non fetched lazy objects

I finally found the solution! thanks to indybee for giving me a clue. The tutorial Spring 3.1, Hibernate 4 and Jackson-Module-Hibernate have a good solution for Spring 3.1 and earlier versions. But since version 3.1.2 Spring have his own MappingJackson2HttpMessageConverter with almost the same functionality as the one in the tutorial, so we don’t need … Read more

How to map an entity field whose name is a reserved word in JPA

With Hibernate as JPA 1.0 provider, you can escape a reserved keyword by enclosing it within backticks: @Column(name=”`open`”) This is the syntax inherited from Hiberate Core: 5.4. SQL quoted identifiers You can force Hibernate to quote an identifier in the generated SQL by enclosing the table or column name in backticks in the mapping document. … Read more

How do I call the default deserializer from a custom deserializer in Jackson

As StaxMan already suggested you can do this by writing a BeanDeserializerModifier and registering it via SimpleModule. The following example should work: public class UserEventDeserializer extends StdDeserializer<User> implements ResolvableDeserializer { private static final long serialVersionUID = 7923585097068641765L; private final JsonDeserializer<?> defaultDeserializer; public UserEventDeserializer(JsonDeserializer<?> defaultDeserializer) { super(User.class); this.defaultDeserializer = defaultDeserializer; } @Override public User deserialize(JsonParser jp, … Read more

Hibernate Annotations – Which is better, field or property access?

There are arguments for both, but most of them stem from certain user requirements “what if you need to add logic for”, or “xxxx breaks encapsulation”. However, nobody has really commented on the theory, and given a properly reasoned argument. What is Hibernate/JPA actually doing when it persists an object – well, it is persisting … Read more

How does spring.jpa.hibernate.ddl-auto property exactly work in Spring?

For the record, the spring.jpa.hibernate.ddl-auto property is Spring Data JPA specific and is their way to specify a value that will eventually be passed to Hibernate under the property it knows, hibernate.hbm2ddl.auto. The values create, create-drop, validate, and update basically influence how the schema tool management will manipulate the database schema at startup. For example, … Read more

Hibernate: hbm2ddl.auto=update in production?

No, it’s unsafe. Despite the best efforts of the Hibernate team, you simply cannot rely on automatic updates in production. Write your own patches, review them with DBA, test them, then apply them manually. Theoretically, if hbm2ddl update worked in development, it should work in production too. But in reality, it’s not always the case. … Read more

Hibernate throws MultipleBagFetchException – cannot simultaneously fetch multiple bags

I think a newer version of hibernate (supporting JPA 2.0) should handle this. But otherwise you can work it around by annotating the collection fields with: @LazyCollection(LazyCollectionOption.FALSE) Remember to remove the fetchType attribute from the @*ToMany annotation. But note that in most cases a Set<Child> is more appropriate than List<Child>, so unless you really need … Read more

Difference between FetchType LAZY and EAGER in Java Persistence API?

Sometimes you have two entities and there’s a relationship between them. For example, you might have an entity called University and another entity called Student and a University might have many Students: The University entity might have some basic properties such as id, name, address, etc. as well as a collection property called students that … Read more