I\'m new to using Hibernate with Java. I\'m getting the following exception. The stuff that I found online regarding this error didn\'t seem to help. Any ideas? The Exception:<
Try adding a class
element under persistence-unit
, in your persistence.xml
file.
<?xml version="1.0" encoding="UTF-8"?>
<persistence ...>
<persistence-unit name="unit">
<class>com.icesoft.icefaces.samples.datatable.jpa.ApplPerfStats</class>
...
</persistence-unit>
<persistence>
I haven't done much more than that with JPA/EntityManager, so I don't know if there's a way to add an entire package. AFAIK, when using hibernate.cfg.xml
, each persistent class has to be specified directly.
I was having the same problem and I solved by adding aspectj entries to my pom.xml see below. I guess it makes sense if you are using annotations. Otherwise you need to specify the mappings in the XML file. I had this problem from a project that was using a jar with JPA annotations.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.2</version> <!-- NB: do use 1.3 or 1.3.x due to MASPECTJ-90 - wait for 1.4 -->
<dependencies>
<!-- NB: You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<configuration>
<weaveDependencies>
<weaveDependency> <groupId>your.project</groupId> <artifactId>your.artifact</artifactId> </weaveDependency>
</weaveDependencies>
</configuration>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
It happened to me until I started to use the full class name, e.g.:
String queryString = "select count(c) from com.my.classes.package.ApplPerfStats c";
But I don't like this approach, because it's refactoring-unfirendly. A more tractable one would be:
String queryString = "select count(c) from " + ApplPerfStats.class.getName() + c";
javashlook's solution seems to be a shortcut for that - but it adds more XML configuration, which I try to avoid. If only there was an annotation-based way to specify that...
You should specify a column to do the count on
select count(c.someColumn) from ApplPerfStats c
Or try a count(*)
select count(*) from ApplPerfStats c
I was also face this problem fixed by this ...
You haven't declared your entity classes in persistence.xml config file:
<property name="hibernate.archive.autodetection" value="class, hbm"/>
I faced this issue but in my case the problem was due to gradle version.
When I changed my system from linux to mac then I had to switch from gradle-1.0-milestone-3 to gradle-1.0-milestone-4 as milestone-3 does not work in OSX. And in gradle-1.0-milestone-4 I faced the same issue then I had to degrade my gradle version to gradle-1.0-milestone-1. Now it is working fine