1

In my User class, I'm trying to add the symbols @id and @column.

I'm getting a compile error:

cannot find symbol class id/column.

I'm using IDEA.

In the docs, I don't see any reference for @Id and @Column: http://docs.jboss.org/hibernate/stable/annotations/api/

I have this in my pom.xml:

<dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>3.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.14</version>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.perf4j</groupId>
            <artifactId>perf4j</artifactId>
            <version>0.9.13</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.1rc2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-hibernate3</artifactId>
            <version>2.0.8</version>
        </dependency>
        <dependency>
            <groupId>hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.1beta4</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.1beta4</version>
        </dependency>


    </dependencies>
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • Hard to tell just from this: Perhaps show the class that doesn't compile. BTW you have hibernate-annotations listed twice in your dependencies. And why are you using a two-year old beta version? – leonm Jul 17 '10 at 10:13

3 Answers3

2

Java is case sensitive. It's @Id and @Column. Also, those are JPA annotations, i.e. they're not part of Hibernate but of Java EE (in the javax.persistence package). The corresponding Hibernate annotations are @PrimaryKey and @Column from the org.hibernate.mapping package.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
2

If you want to use the JPA 1.0 implementation, you need the following dependencies:

<properties>
  <org.hibernate.version>3.4.0.GA</org.hibernate.version>
</properties>
<repositories>
  <repository>
    <id>repository.jboss.org-public</id>
    <name>JBoss Public Repository Group</name>
    <url>https://repository.jboss.org/nexus/content/groups/public</url>
  </repository>
</repositories>
<dependencies>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${org.hibernate.version}</version>
  </dependency>
  <!-- Hibernate uses slf4j for logging, we use log4j as backend -->
  <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
  </dependency>
</dependencies>

If you want to use the JPA 2.0 implementation, simply replace the org.hibernate.version by:

<properties>
  <org.hibernate.version>3.5.3-Final</org.hibernate.version>
</properties>

In both cases, the above Hibernate dependency will give you everything you need transitively.


As you may have noticed, Hibernate uses SLF4J while Spring uses Jakarta Commons Logging. I suggest to configure Spring to use SLF4J as well as explained in this previous answer.

See also

Community
  • 1
  • 1
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • @Blankman: JPA is a standard that Hibernate implements (the JPA implementation is provided by *Hibernate Entity Manager* which depends on *Hibernate Annotations*). I would recommend using JPA over the Hibernate specific annotations. – Pascal Thivent Jul 17 '10 at 20:27
0

What you need is java's persistence annotation You can either add dependency of

javax.persistence:persistence-api

Although adding dependency to hibernate entity manager will resolve you transitively, I would still recommend to add dependencies that you have really used in your artifact.

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131