Announcement Announcement Module
Collapse
No announcement yet.
Adding servlet api to spring data jpa example renders it unworking Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding servlet api to spring data jpa example renders it unworking

    Hello,
    I'm trying to add integration tests to my project, so to understand how to do it I copied the spring data jpa showcase here:
    https://github.com/spring-projects/s...a-jpa-showcase

    I now have to convert it to a web project but just adding the javaee dependencies on the pom file:
    <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
    </dependency>


    give me this error while trying to execute tests:

    /Work/spring-data-jpa-showcase/src/snippets/java/org/springframework/data/jpa/showcase/snippets/AccountPredicates.java:5: error: cannot find symbol
    import org.springframework.data.jpa.showcase.core.QAccoun t;
    ^
    symbol: class QAccount
    location: package org.springframework.data.jpa.showcase.core
    /Work/spring-data-jpa-showcase/src/snippets/java/org/springframework/data/jpa/showcase/snippets/AccountPredicates.java:16: error: cannot find symbol
    private static QAccount $ = QAccount.account;
    ^
    symbol: class QAccount
    location: class AccountPredicates
    [ERROR] execute error
    java.lang.RuntimeException: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/GenerationType
    at com.sun.tools.javac.main.Main.compile(Main.java:55 3)
    at com.sun.tools.javac.api.JavacTaskImpl.doCall(Javac TaskImpl.java:129)
    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTa skImpl.java:138)

    [...]
    Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/GenerationType
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :760)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)

    Anyone can help me explain why this behavior and how to solve it?

    Thanks in advance

  • #2
    Hi,

    The example you are using is not a web based application and simply adding a jar file will not make it a web project. I would suggest you look at a sample spring web application and integrate the JPA sample code into that project. If you are looking to do integration tests to your database them there is no requirement for any JavaEE jar files in the first place.

    As for your exception see below:

    It looks like you have hit a similar problem as referred to in this blog http://www.mkyong.com/hibernate/java...in-class-file/

    In summary it states that "does not contains any method bodies, but the APIs name only. Which is not suitable to use for running or deploying along with your application."

    The solution stated in that blog is to "The good practice is always get the original full version of javaee.jar file from the http://java.sun.com/javaee/. Just download and install the J2EE SDK, and the javaee.jar can be found in the “\J2EE_SDK_FOLDER\lib” folder. Include it into your local Maven repository or project classpath will get rid of the above error message."

    If you need more help I would direct you question to Stackoverflow using the tag "spring-data" as this forum is being move to Stackoverflow where the large spring community is more active.



    Comment

    Working...
    X