[Solved] Using relationships like @OneToMany, @ManyToOne in hibernate is good practice or not? [closed]

Regardless of good practice, the point here is you have two options to model this: Elect to manually assign the Department‘s Id on the Employee. Associate the new Employee with an existing Department entity at save. Which you pick really depends on a number of factors. Often the former is chosen when working with legacy … Read more

[Solved] JPA EntityManager find method doesn’t work [closed]

You can get CustomerMapping by cardId using JPQL. A more optimal solution will be to use projections. public String getCustomerMappingCustomerId(String cardId) { getEntityManager(); CustomerMapping result = first(em.createQuery( “select c from CustomerMapping c where c.cardId = :cardId”) .setParameter(“cardId”, cardId).getResultList()); return result == null ? null : result.getCustomerId(); } private static <T> T first(List<T> items) { return … Read more

[Solved] How to properly use findBySomeOtherId not findById in Spring data jpa?

Please use this InterviewStatus findByInterviewId(Interviews interviewId); where interviewId is gotten by running Interviews findById(Long id). Due to the datatype conflict, it is ok that you pass in as parameter the expected datatype. so it is expecting Interviews not Integer, but you have integer. in this case, you get Interviews using the integer then pass the … Read more

[Solved] How To configure Hibernate as a JPA provider for Payara/Glassfish 4.1? [closed]

Found the answer in this article : Hibernate 5 in Payara Briefly, add Hibernate dependencies in your pom.xml, replace payara/glassfish jboss-logging.jar /lib with latest and then restart server. Your project should have in the persistence.xml its provider org.hibernate.jpa.HibernatePersistenceProvider and property name=”hibernate.transaction.jta.platform” value=”org.hibernate.service.jta.platform.internal.SunOneJtaPlatform” solved How To configure Hibernate as a JPA provider for Payara/Glassfish 4.1? [closed]

[Solved] Advantage of using JPA [closed]

If you want do decrease the degree of coupling to a certain orm tool, then jpa is a good choice. It defines a set of well defined apis that you may use with any existing persistence provider. Some projects require a specific persistence provider. Hence the jpa allows you to apply (not only) the basic … Read more

[Solved] org.apache.openjpa.persistence.PersistenceException: null

I’ll document all my solutions to this problem. This is the 1st resolution. The clue was here. I upgraded Open JPA from 2.2.0 to 2.2.2 & the exception went away, so it appears that it was a bug. This happened again. I was missing cglib.2.2.3.zip and/or cglib-nodep-2.2.3.jar. solved org.apache.openjpa.persistence.PersistenceException: null

[Solved] Why the mapping.xml and configuration.xml has to be outside the pojo package?

I have just started to learn the Hibernate and found this in various online sites : mapping.xml and config.xml has to be defined outside the pojo package? You can put xml configurations whenever you want. For an example SessionFactory factory = new Configuration().configure().buildsessionFactory(); Configure a session factory from the default hibernate.cfg.xml. It is the same … Read more

[Solved] Three joined tables query with many-to-many relationship in JPA [closed]

I think your SQL might look something like this: SELECT * FROM Hospital WHERE Postcode = 3000 AND Hospital_id IN (SELECT Hospital_id FROM Hospital_Medical hm INNER JOIN Medical_Service m ON hm.Medical_id = m.Medical_id where Medical_name=”Emergency”) AND Hospital_id IN (SELECT Hospital_id FROM Hospital_Language hl INNER JOIN Language_Service l ON hl.Language_id = l.Language_id where Language_name=”English”) solved Three … Read more