IDEA with Hibernate does not resolve duplicate class names correctly in session.createSelectionQuery
Answered
I have two packages in my app that provide @Entity classes for Hibernate:
lu.myCompany.myAppA.model.db.appName.
lu.myCompany.myAppB.model.db.appName.
Both packages include an entity with the name Counterpart.java
When I do something like this:
import lu.myCompany.myAppA.model.db.appName.Counterpart;
@Repository
public class appNameDAO {
private final SessionFactory sessionFactory = HibernateUtil.getSessionFactoryGifsDb();
public String getNameForCounterpartByCounterpartId(String counterpartId) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
List<Counterpart> cps = session.createSelectionQuery("from Counterpart cp where cp.custodianCpId = :counterpartId", Counterpart.class) I have an existing connection to both databases in my Intellij database explorer.
Then the custodianCpId is underlined red and not recognized. Also, the auto completion (CTRL + Space) is providing the suggestions for the Counterpart entity from the other package, not the one I referenced in the current class. If I add the package name in front of Counterpart, everything works just fine:
List<Counterpart> cps = session.createSelectionQuery("from lu.myCompany.myAppA.model.db.appName.Counterpart cp where cp.custodianCpId = :counterpartId", Counterpart.class)
.setParameter("counterpartId", counterpartId)
.getResultList();I think that is a bug.
1 comment
Sort by
Date
Votes
Hi Twanger, can you provide more info about the project, e.g., the Hibernate version used by the project, Gradle/Maven based, using Spring/JPA or not? It would be great if you could provide a pom.xml or build.gradle file, thanks.
Please sign in to leave a comment.