views:

54

answers:

3

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>
+2  A: 

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
i can't get org.hibernate.annotations.Id to work...hmmm...I have: <dependency> <groupId>hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>3.1beta4</version> </dependency>
Blankman
@Blankman: I was mistaken about the location of those annotations (@Id is from JPA, not Hibernate). I've corrected the answer.
Michael Borgwardt
+2  A: 

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&lt;/url&gt;
  </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

Pascal Thivent
I thought JPA was a different ORM, allot to learn sheesh!
Blankman
@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
A: 

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