Erro Unknown entity , não sei mais o que fazer!

4 respostas
acjZer0

Estou com esse erro a um tampão já devo ter reconfigurado o spring umas 100x e não consigo resolve-lo, por favor se alguém conseguir me ajudar serei grato.

-------------------ERROR----------------
03:07:36,780 INFO [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221053)] Started in 41s:452ms
03:08:33,210 ERROR [[Spring MVC Dispatcher Servlet]] Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception
org.hibernate.MappingException: Unknown entity: br.com.virtualstore.model.TipoLogradouro
at org.hibernate.impl.SessionFactoryImpl.getEntityPer sister(SessionFactoryImpl.java:580)
at org.hibernate.impl.SessionImpl.getEntityPersister( SessionImpl.java:1365)
at org.hibernate.event.def.AbstractSaveEventListener. saveWithGeneratedId(AbstractSaveEventListener.java :121)

CONFIGURATION FILES

servlet-context
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schem...ng-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <mvc:annotation-driven />
   <mvc:view-controller path="/" view-name="principal"/>
   <context:component-scan base-package="br.com.virtualstore.controller" />
     <mvc:interceptors>
     <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
  </mvc:interceptors>
   <mvc:resources mapping="/resources/**" location="/resources/" />
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="/WEB-INF/messages/messages" />
    <property name="cacheSeconds" value="0" />
  </bean>
   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/pages/"/>
    <property name="suffix" value=".jsp"/>
  </bean>

  <bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="100000"/>
  </bean>

</beans>
persistence-dao
<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:jee="http://www.springframework.org/schema/jee"
  xmlns:lang="http://www.springframework.org/schema/lang"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:util="http://www.springframework.org/schema/util"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...spring-aop.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schem...ng-context.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schem...spring-jee.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schem...pring-lang.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">


    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="locations">
        <list>
        <value>WEB-INF/spring/jdbc.properties</value>
        </list>
      </property>
    </bean>
          
   <tx:annotation-driven transaction-manager="transactionManager" /> 
        
  <!-- Declare a datasource that has pooling capabilities-->   
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close"
        p:driverClass="${app.jdbc.driverClassName}"
        p:jdbcUrl="${app.jdbc.url}"
        p:user="${app.jdbc.username}"
        p:password="${app.jdbc.password}"
        p:acquireIncrement="5"
        p:idleConnectionTestPeriod="60"
        p:maxPoolSize="100"
        p:maxStatements="50"
        p:minPoolSize="10" />

  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
         p:dataSource-ref="dataSource"
         p:configLocation="${hibernate.config}"
         p:configurationClass="org.hibernate.cfg.AnnotationConfiguration"
         p:annotatedPackages="br.com.virtualstore.model"
         p:packagesToScan="br.com.virtualstore.model"/>
      
      
    <!-- Declare a transaction manager-->
  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
            p:sessionFactory-ref="sessionFactory" />
  
 <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
  
  </beans>
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
		
<hibernate-configuration>
  <session-factory>
  	<!-- We're using MySQL database so the dialect needs to MySQL as well-->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    <!-- Enable this to see the SQL statements in the logs-->
    <property name="show_sql">true</property>
    </session-factory>
</hibernate-configuration>
application-context
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schem...-beans-3.0.xsd  http://www.springframework.org/schema/context  http://www.springframework.org/schem...ontext-3.0.xsd  http://www.springframework.org/schema/tx  http://www.springframework.org/schem...ing-tx-3.0.xsd  http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

  <import resource="persistence-dao.xml" />
<context:annotation-config />

 <context:component-scan base-package="br.com.virtualstore.dao" />
 <context:component-scan base-package="br.com.virtualstore.model" />
 <context:component-scan base-package="br.com.virtualstore.service" />
</beans>
CLASSES
package br.com.virtualstore.controller;


import java.io.Serializable;

import javax.annotation.Resource;
import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import br.com.virtualstore.dao.GenericDaoImpl;
import br.com.virtualstore.model.TipoLogradouro;


@Controller
@RequestMapping(value="/test")
public class testController {

	  
	   @Autowired(required=true)
	   GenericDaoImpl dao;
	
	  
	   @Resource(name="tipoLogradouro")
	    TipoLogradouro T;
	   
	@Transactional
	@RequestMapping(method=RequestMethod.GET)
	public String getCreateForm(Model model) {
		T.setNome("lust");
		dao.save(T);
		return "test/view";
	}

	
	
	
	
}
package br.com.virtualstore.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.stereotype.Component;

        @Component("tipoLogradouro")
	@Entity
	@Table(name="tipo_logradouro")
	public class TipoLogradouro implements Serializable {

			private static final long serialVersionUID = -8825404991137841920L;

	@Id
	@Column(name="id_tipo_logradouro")
	private Long id;
	
	@Column(name="nome")
	private String nome;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}}
package br.com.virtualstore.controller;

@Controller
@RequestMapping(value="/test")
public class testController {

	   @Autowired(required=true)
	   GenericDaoImpl dao;
		  
	@Transactional
	@RequestMapping(method=RequestMethod.GET)
	public String getCreateForm(Model model) {
		 TipoLogradouro T = new TipoLogradouro();
		T.setNome("lust");
		dao.save(T);
		return "test/view";
	}
}

Libs que uso, ja tenti usar tbm a javassist-3.12.1.GA.jar sem sucesso , utilizo tbm as libs presentes no boss-5.1.0.GA
[img]http://img515.imageshack.us/img515/2415/10801748.png[/img]

4 Respostas

narciso.benigno

dentro da sua sessionfactory e coloca o seguinte:

<property name="annotatedClasses"> <list> <value>br.com.virtualstore.model.TipoLogradouro</value> </list> </property>

acjZer0

Adicionei e continua o erro, muito estranho esse erro…

Emyus

é o que falta no hibernate.cfg

acjZer0

coloquei e nao funcionou :frowning:

Criado 3 de fevereiro de 2011
Ultima resposta 4 de fev. de 2011
Respostas 4
Participantes 3