gpt4 book ai didi

java - Spring + Hibernate SQL 实体名称未解析

转载 作者:太空宇宙 更新时间:2023-11-04 15:00:42 24 4
gpt4 key购买 nike

在 Hibernate SQL 中,类名(实体)无法识别。编译时错误,我已完成以下操作

实体类

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

道类

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 配置文件

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

编译时错误显示“无法解析符号 UserEntity”...问题是什么?

最佳答案

将默认构造函数和可序列化接口(interface)添加到实体 bean 并立即检查...

关于java - Spring + Hibernate SQL 实体名称未解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22606636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com