0

Currently my project looks like:

Root

 -- Common (Contains Entity classes)

 -- Processor (Refers Common)

Common and Controller are both maven projects (each deployed in its own Jetty instance - common is user-facing jetty server and processor is back-end daemon that currently runs in jetty server too as it is designed for responding to some internal http-requests too). Root contains the parent pom for both Common and Processor

When I do DB related operations in Common, it works pretty well.

But when I call the same functions from Processor, it gives an error:

java.lang.IllegalArgumentException: 

org.hibernate.hql.internal.ast.QuerySyntaxException:

User is not mapped [select users from User users fetch all properties]

    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1679)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:294)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:129)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:96)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:248)
    at com.myproject.common.persistence.UserManager.selectStar(UserManager.java:110)

UserManager.selectStar() works perfectly well from common though. Both Common and Processor have query-dsl plugin to generate Q-files. Both Common and Processor have META-INF/persistence.xml file too.

UserManager instantiates EntityManagerFactory as:

emf = Persistence.createEntityManagerFactory("world");

where "world" is the name of my DB.

./common/src/main/resources/META-INF/persistence.xml
./processor/src/main/resources/META-INF/persistence.xml

Processor has a dependency on common as:

<!-- language: lang-xml -->
<dependency>
  <groupId>com.mock</groupId>
  <artifactId>common</artifactId>
</dependency>

All dependency versions are also being managed in the Root pom's <dependencyManagement> section.

user2250246
  • 3,807
  • 5
  • 43
  • 71
  • Possible duplicate of [Unable to call Hibernate/QueryDSL from another maven subproject](http://stackoverflow.com/questions/32857422/unable-to-call-hibernate-querydsl-from-another-maven-subproject) – user2250246 Oct 03 '15 at 03:18

3 Answers3

0

looks like you don't have your SessionFactory properly configured in your Processor project.

Can you please add your pom files to the question and your hibernate configuration files?

I guess your processor project is the web front end and your common project is your domain?

If this is the case you should add your common project as dependency of the processor project, then you will be able to launch queries from processor project, because you will be using your common project hibernate context.

Regards.

gorri
  • 13
  • 3
  • Thanks gorri! I have re-posted the question with full code at http://stackoverflow.com/questions/32857422/unable-to-call-hibernate-querydsl-from-another-maven-subproject Please reply there, I will delete this question shortly – user2250246 Sep 30 '15 at 03:50
0

Information you provided is not sufficient. Are you using Spring, is this is a WebApp or Standalone?

Besides you don't need to create two persistence.xml files. Check how are you creating EntityManager -> based on witch persistence-unit?

KirkoR
  • 788
  • 6
  • 13
  • Thanks ! I have re-posted the question with full code at http://stackoverflow.com/questions/32857422/unable-to-call-hibernate-querydsl-from-another-maven-subproject Please reply there, I will delete this question shortly – user2250246 Sep 30 '15 at 03:49
0

Please, provide all the necessary information as other people requested. Is this a webapp? Are you using Spring? Please add full code for pom.xml files.

And as other fellows said, you only need one persistence.xml. All queries executed on the database should act in the same hibernate context.

Besides, if you have separation of responsabilities your processor project shouldn't be executing any query, just requesting some common project layer to execute it and return the result.

regards.

gorri
  • 13
  • 3
  • I have re-posted the question with full code at http://stackoverflow.com/questions/32857422/unable-to-call-hibernate-querydsl-from-another-maven-subproject Please reply there, I will delete this question shortly – user2250246 Sep 30 '15 at 03:49