what am i missing for using hibernate annotation?
Asked Answered
S

2

10

i am trying to create a basic hibernate entity POJO using latest hibernate and i have added the necesary jar files i downloaded from hibernate website.

the problem is when i add the line @Table(name = "user")

it complains of a compile error:

The annotation @Table must define the attribute appliesTo

full code below:

package com.jr.entities.users;

import java.io.Serializable;

import org.hibernate.annotations.Entity;
import org.hibernate.annotations.Table;

@Entity
@Table(name = "user")
public class DAOuser implements Serializable{
    
    private String uid;
    private String emailAddress;
    private String username;
    private String password;
    

}

In this example link http://www.roseindia.net/hibernate/hibernateannotations/hibernate-annotations-tutorial.shtml it says that it does not need to applyTo value to be set? Am I missing something? I created a simple EJB3 project in eclipse J2ee if it helps.

Thanks in advance

Slogan answered 19/4, 2011 at 16:26 Comment(0)
P
18

There are two sets of persistence annotations (@Entity and @Table) - JPA annotations (in package javax.persistence) and Hibernate annotations (in package org.hibernate.annotations). Note that example uses JPA annotations, whereas your code uses Hibernate annotations, so your code doesn't compile because these annotations have different sets of attributes.

So, you need to change packages in your import statements.

Usually you should use JPA annotations unless you need some features provided only by Hibernate annotations.

Prothalamion answered 19/4, 2011 at 16:34 Comment(2)
ahh ok. is there an example on how to do the above in pure hibernate annotations? can i mix hibernate with jpa annotations? I.e use jpa annotations for my entities and use Hibernate.cfg.xml to configure the data source?Slogan
@jonney: See docs.jboss.org/hibernate/annotations/3.5/reference/en/html. You can mix Hibernate and JPA annotations as you want.Prothalamion
M
-2

appliesTo is the name containing the target table:

@Table(appliesTo="user")
Mallissa answered 12/3, 2015 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.