나는 예외를 얻고있다 org.hibernate.MappingException을 hibernate4 : 알 수없는 엔티티를 com.pro.entity.Userorg.hibernate.MappingException는 알 수없는 엔티티는 spring4
내가 유사한 게시물을 보았다 그러나 거의 모두가 솔루션을 제공합니다 @Entity 어노테이션을 Hibernate 대신 javax.persistence로 변경합니다. 필자는 처음부터 정확한 주석을 사용하고 있기 때문에 유용하지 않았다. 엔티티 클래스 dao와 서블릿 컨텍스트에 대한 코드는 다음과 같습니다.
package com.pro.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="user")
public class User {
private static final long serialVersionUID = 1L;
@Id
@Column(name="userid")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String id;
@Column(name="password")
private String password;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
다오 클래스 코드 :
public User getUser(String userid)
{
Session session = this.sessionFactory.getCurrentSession();
User user = (User)session.load(User.class, userid);
return user;
}
의 context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/orm
http://www.springframework.org/schema/orm/spring-orm-4.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd">
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url"
value="jdbc:mysql://localhost:3306/pro?useSSL=false" />
<beans:property name="username" value="user" />
<beans:property name="password" value="password" />
</beans:bean>
<beans:bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">${hibernate.dialect}</beans:prop>
<beans:prop key="hibernate.show_sql">${hibernate.show_sql}</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory"></beans:property>
</beans:bean>
<tx:annotation-driven transaction-manager="transactionManager"/><tx:annotation-driven/>
<beans:bean id="persistenceExceptionTranslationPostProcessor" class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"></beans:bean>
<context:component-scan base-package="com.pro.controller" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
</beans:beans>
내의 context.xml 파일에 다음을 추가하는 데 필요한 솔루션을 ....있어 ... 당신은 패키지를 지정하지 않은 엔티티를 수동으로 스캔하거나 등록합니다. 그것 없이는, 당신의 엔티티는 그것에 대한 주석과 상관없이 단순히 존재하지 않는다. –
User.java를 어디에 두겠습니까? 그것은''com.pro.entity'' 패키지 안에 있습니까? –
여기에 게시하기 전에 코드를 실제로 변경했지만 프로젝트 구조가 스프링 사양에 따라 다르다고 믿습니다. – sbajpai