开发者

what am i missing for using hibernate annotation?

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 = &qu开发者_Go百科ot;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.


appliesTo is the name containing the target table:

@Table(appliesTo="user")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜