Boa tarde pessoal, eu baixei jtds-1.2.2-dist.zip, e então tentei configurar meu persistence.xml para acessar o banco de dados SQL Server, porém não está funcionando.
aqui está minha classe de teste:
/**
*
*/
package br.gov.ce.srh.siscontv.model;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import br.gov.ce.srh.siscontv.model.entity.Pessoa;
import br.gov.ce.srh.siscontv.model.entity.Usuario;
/**
* @author euclides filizola
*
* SRH - Secretaria de Recursos Hídricos
*
*/
public class JPAUtil {
public static void main(String[] args) {
/*
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("bancoLocal");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
People pl = em.find(People.class, 1);
pl.setName("Euclies Filizola ");
Address add = em.find(Address.class, 1);
add.setAddress("Endereço alterado");
Usuario usuario = em.find(Usuario.class, 1);
System.out.println("Nome do usuario: "+usuario.getNomeUsuario());
em.getTransaction().commit();
em.close();
emf.close();
*/
EntityManagerFactory emf2 = Persistence
.createEntityManagerFactory("BDSERV");
EntityManager em2 = emf2.createEntityManager();
em2.getTransaction().begin();
Pessoa p = em2.find(Pessoa.class, 1);
System.out.println("Nome da pessoa: "+p.getNome());
em2.getTransaction().commit();
em2.close();
emf2.close();
}
}
aqui está meu 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="BDSERV" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>br.gov.ce.srh.siscontv.model.entity.Pessoa</class>
<properties>
<property name="hibernate.connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="hibernate.connection.username" value="user_sicf" />
<property name="hibernate.connection.password" value="systemsicf" />
<property name="hibernate.connection.url" value="jdbc:jtds:sqlserver://172.31.128.25/bdserv;" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
</properties>
</persistence-unit>
</persistence>
aqui minha classe pessoa:
package br.gov.ce.srh.siscontv.model.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="[DADOS DO SERVIDOR]")
public class Pessoa implements java.io.Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name="MATRÍCULA")
private Integer matricula;
@Column(name="NOME")
private String nome;
/**
*
*/
public Pessoa() {
}
/**
* @param nome
*/
public Pessoa(String nome) {
this.nome = nome;
}
/**
* @return the nome
*/
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @param matricula the matricula to set
*/
public void setMatricula(Integer matricula) {
this.matricula = matricula;
}
/**
* @return the matricula
*/
public Integer getMatricula() {
return matricula;
}
}
Alguém poderia me da uma força ?