PROBLEMA com JPA + HIBERNATE + SQL SERVER + SPRING :: Unknown entity:

4 respostas
M

Olá, estou tendo um problema no desenvolvimento de um aplicativo que utiliza jpa com hibernate e spring. O bd é o sql server.
Ao tentar gravar no banco da a seguinte mensagem:

Unknown entity: br.com.scp.esuporte2.modelo.Depto

segue o persistence.xml e o a applicationContext.xml
obs(utilizo esta configuracao com Mysql e PostgreSql e nao tenho nenhum problema)

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
	xmlns="http://java.sun.com/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

	<persistence-unit name="scp">
		
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
                

               <properties>
			<property name="hibernate.archive.autodetection"
				value="class, hbm" />

			<!--Configuracoes de dialeto e conexao-->
			<property name="hibernate.dialect"
				value="org.hibernate.dialect.SQLServerDialect" />
			<property name="hibernate.connection.driver_class"
				value="net.sourceforge.jtds.jdbc.Driver" />
			<property name="hibernate.connection.url"
				value="jdbc:jtds:sqlserver://host:1433/scp" />
			<property name="hibernate.connection.username"
				value="usu" />
			<property name="hibernate.connection.password"
				value="senha" />

			<!--Configuracoes de Debug-->
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.format_sql" value="true" />
			<property name="use_sql_comments" value="true" />
			
                        <!--Configuração do pool de c3p0-->           
                         <property name="hibernate.c3p0.min_size" value="5" />
                         <property name="hibernate.c3p0.max_size" value="20" />
                         <property name="hibernate.c3p0.timeout" value="300" />
                         <property name="hibernate.c3p0.max_statements" value="50" /> 
                         <property name="hibernate.c3p0.idle_test_period" value="3000"/>                      
			
			
		</properties>

		
		
		
	</persistence-unit>
</persistence>

applicationContext.xml

<?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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="persistenceUnitName" value="scp" />
	</bean>

        <context:component-scan base-package=br.com.scp.esuporte2.controller" />

        <context:annotation-config />

       <bean id="transactionManager"
		class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory"
			ref="entityManagerFactory" />
	</bean>
    
    
       <tx:annotation-driven />
	
	
	<bean id="DeptoDao" class="br.com.scp.esuporte2.dao.imp.DeptoDaoImp" />
	
		
</beans>

Entidade Depto.java

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="depto", schema="esuporte2")
public class Depto {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer codDepto;
	@Column(length=100)
	private String nome;
	private String descricao;
        
        public Depto(){}
        //gets e sets....

caso alguém possa ajudar já vai meu mt obrigado
valew… um abraço

4 Respostas

A

Eu faria um teste de tirar o schema=“esuporte2” da classe. Nao sou expert em sql server mas da uma lida aqui (http://msdn.microsoft.com/en-us/library/ms190387.aspx)

M

Ola aeugenio,

cara tentei tirar o schema e continua o mesmo problema…

M

Faz o seguinte teste:
Acrescente o mapeamento no persistence.xml

<persistence-unit name="scp">
   <class>br.com.scp.esuporte2.modelo.Depto</class>

   ...
</persistence-unit>
M

Ola Marcelo, ja tentei isto e nada. :frowning:

Criado 19 de março de 2009
Ultima resposta 20 de mar. de 2009
Respostas 4
Participantes 3