When and why JPA entities should implement the Serializable interface?

The question is in the title. Below I just described some of my thoughts and findings. When I had a very simple domain model (3 tables without any relations), all my entities did NOT implement the Serializable interface. But when the domain model became more complex, I got a RuntimeException, saying that one of my … Read more

Difference Between One-to-Many, Many-to-One and Many-to-Many?

Ok so this is probably a trivial question but I’m having trouble visualizing and understanding the differences and when to use each. I’m also a little unclear as to how concepts like uni-directional and bi-directional mappings affect the one-to-many/many-to-many relationships. I’m using Hibernate right now so any explanation that’s ORM related will be helpful. As … Read more

javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional

I don’t understand what is the actual difference between annotations javax.transaction.Transactional and org.springframework.transaction.annotation.Transactional? Is org.springframework.transaction.annotation.Transactional an extension of javax.transaction.Transactional or they have totally different meaning? When should each of them be used? Spring @Transactinal in service layer and javax in DAO? Thanks for answering. 4 Answers 4

What is the proper way to re-attach detached objects in Hibernate?

I have a situation in which I need to re-attach detached objects to a hibernate session, although an object of the same identity MAY already exist in the session, which will cause errors. Right now, I can do one of two things. getHibernateTemplate().update( obj ) This works if and only if an object doesn’t already … Read more

What are the differences between the different saving methods in Hibernate?

Hibernate has a handful of methods that, one way or another, takes your object and puts it into the database. What are the differences between them, when to use which, and why isn’t there just one intelligent method that knows when to use what? The methods that I have identified thus far are: save() update() … Read more

Can someone explain mappedBy in JPA and Hibernate?

I am new to hibernate and need to use one-to-many and many-to-one relations. It is a bi-directional relationship in my objects, so that I can traverse from either direction. mappedBy is the recommended way to go about it, however, I couldn’t understand it. Can someone explain: what is the recommended way to use it? what … Read more

How does JPA orphanRemoval=true differ from the ON DELETE CASCADE DML clause

I am a little confused about the JPA 2.0 orphanRemoval attribute. I think I can see it is needed when I use my JPA provider’s DB generation tools to create the underlying database DDL to have an ON DELETE CASCADE on the particular relation. However, if the DB exists and it already has an ON … Read more

Make hibernate ignore class variables that are not mapped [duplicate]

This question already has answers here: What is the easiest way to ignore a JPA field during persistence? (10 answers) Closed 5 years ago. I thought hibernate takes into consideration only class variables that are annotated with @Column. But strangely today when I added a variable (that is not mapped to any column, just a … Read more