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
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.