@Cache annotation usage error
Asked Answered
F

5

10

I added the following annotation to enable cache to one of my EJB3 entities, to test caching with ehCache, where I use Hibernate as the persistence provider:

....
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "F")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@NamedQueries({ @NamedQuery(name = "F.findAll", query = "SELECT f FROM F f")})
public class F implements Serializable {
   .....
}

I added the following to persistence.xml:

<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<property name="hibernate.cache.provider_configuration_file_resource_path" value="/ehcache.xml"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>

And when I try to compile I get the following error:

/persistence/F.class): warning: Cannot find annotation method 'usage()' in type 'org.hibernate.annotations.Cache': class file for org.hibernate.annotations.Cache not found An exception has occurred in the compiler (1.6.0_16). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you. com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.hibernate.annotations.CacheConcurrencyStrategy not found

Can anyone help me out here and let me know what I need to do or am doing wrong currently ?

Filch answered 23/10, 2009 at 14:46 Comment(0)
H
4
@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)

will solve the problem

Hames answered 9/9, 2017 at 14:51 Comment(0)
F
2

Well .. I got it to work eventually. The fix for it is really strange and really does seem to be a reported bug.

What I needed to do was to add all the Hibernate libraries to my Netbeans web/war project as well. Once I did that, the errors went away.

This was strange because the Hibernate libraries were already included in the ear project which was also in the web project library.

Filch answered 18/11, 2009 at 14:40 Comment(2)
Given that, you should accept your answer so that this question is closed.Rockwood
Given that, you should also mention the missing dependencies in your answerJegar
P
0

You're not doing anything wrong - your annotations are fine.

Judging by the error message it's a compiler bug. You can:

  1. Update to the latest JDK version (1.6.0_16-b01).
  2. Rearrange your annotations and hope that compiler bug will not be triggered. Yes, that sounds silly but I have used @Cache declarations extensively (as I'm sure many other people did) and I have no problems with compilation meaning you just got (un)lucky.
  3. Try a different compiler (build from Eclipse)
  4. Submit a bug report to Sun.
Pereyra answered 23/10, 2009 at 17:20 Comment(0)
L
0

You only have to add hibernate-annotations jars to your web/war project.

Loran answered 13/9, 2010 at 23:45 Comment(0)
D
0

I solved this by changing the hibernate libraries from provided to compile in the pom of a maven multi module project.

Dulciedulcify answered 20/6, 2011 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.