How to map a composite key with JPA and Hibernate?

To map a composite key, you can use the EmbeddedId or the IdClass annotations. I know this question is not strictly about JPA but the rules defined by the specification also applies. So here they are: 2.1.4 Primary Keys and Entity Identity … A composite primary key must correspond to either a single persistent field or property or to a … Read more

Advice on loopback.js vs express js

Planning to build an enterprise level application using node js. Have already worked on express js for a few projects. When researching for other possible frameworks, came across loopback js. Loopback.js, a new framework(3-4 years) built over express framework. The initial configuration and set up of the application was so quick, as i able to … Read more

Hibernate throws org.hibernate.AnnotationException: No identifier specified for entity: com..domain.idea.MAE_MFEView

You are missing a field annotated with @Id. Each @Entity needs an @Id – this is the primary key in the database. If you don’t want your entity to be persisted in a separate table, but rather be a part of other entities, you can use @Embeddable instead of @Entity. If you want simply a … Read more

How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error

You should include cascade=”all” (if using xml) or cascade=CascadeType.ALL (if using annotations) on your collection mapping. This happens because you have a collection in your entity, and that collection has one or more items which are not present in the database. By specifying the above options you tell hibernate to save them to the database when saving their parent.

What is the “N+1 selects problem” in ORM (Object-Relational Mapping)?

Let’s say you have a collection of Car objects (database rows), and each Car has a collection of Wheel objects (also rows). In other words, Car → Wheel is a 1-to-many relationship. Now, let’s say you need to iterate through all the cars, and for each one, print out a list of the wheels. The naive O/R implementation would do the following: And then for each Car: … Read more

How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error

You should include cascade=”all” (if using xml) or cascade=CascadeType.ALL (if using annotations) on your collection mapping. This happens because you have a collection in your entity, and that collection has one or more items which are not present in the database. By specifying the above options you tell hibernate to save them to the database when saving their parent.