简体   繁体   中英

Spring + Hibernate SQL entity name not resolved

In Hibernate SQL, Class Name(Entity) not recognised.Compile time error, I have done following

Entity Class

import javax.persistence.*;
@Entity
@Table(name="user")
public class UserEntity {
    @Id
    @Column(name="id")
    @GeneratedValue
    private int id;

    @Column(name="name")
    private String name;

    @Column(name="address")
    private String address;

     //Getter And Setter 

Dao Class

import com.springapp.model.UserEntity;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public class UserDaoServiceImpl implements UserDaoService{
    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public void addUser(UserEntity user) {
         this.sessionFactory.getCurrentSession().save(user);
    }

    @Override
    public List<UserEntity> findAllUser() {
       return this.sessionFactory.getCurrentSession().createQuery("from UserEntity").list();
    }
}

Hibernate Config File

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <mapping class="com.springapp.model.UserEntity" />
    </session-factory>
</hibernate-configuration>

Compile time error says " Can't resolve symbol UserEntity "...What is the problem?

向实体bean添加默认构造函数和Serializable接口,并立即检查...

you cannot create a table with name user it is a reserved key word. try changing it to something like user-entity it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM