1
I searched about how to set up the file persistence.xml
in a basic way, however, I was even more confused about this configuration.
So I would like to know how I can make a basic configuration in the file persistence.xml
in accordance with the JPA and the Hibernate to access a database on SQL Server 2008?
Information relating to the database:
My Connection String:
"Data Source=CARVALHO-PC\\LOGIXMINESYSTEM;Initial Catalog=TarefaExemplo;Persist Security Info=True;User ID=sa;Password=minhasenha"
The bank has a single table called tarefas
with the fields id int
, descricao VARCHAR(50)
, finalizado int
and data_finalizado DATETIME
.
Project and application structure information:
I’ve added all the libraries (Jars) for Hibernate and JPA and also the JDBC driver for SQL Server.
And the structure of the project is as follows:
...\EXEMPLOHIBERNATE\SRC
├───exemplohibernate
├───META-INF
└───model
Since within the model package there is a single class, class Tarefa
:
package model;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* @author Dener
*/
@Entity
@Table(name="tarefas")
public class Tarefa {
@GeneratedValue
@Id
private Long id;
private String descricao;
private boolean finalizado;
@Column(name = "data_finalizado", nullable = false)
@Temporal(TemporalType.DATE)
private Calendar dataFinalizacao;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public boolean isFinalizado() {
return finalizado;
}
public void setFinalizado(boolean finalizado) {
this.finalizado = finalizado;
}
public Calendar getDataFinalizacao() {
return dataFinalizacao;
}
public void setDataFinalizacao(Calendar dataFinalizacao) {
this.dataFinalizacao = dataFinalizacao;
}
}
This is the class that has the annotations for the Framework. And the other packages do not contain classes yet.
Note:
The sample application is for the desktop platform and the IDE I’m using and Netbeans.
I have a persistence template q made to test in javadb or mysql, will it serve? To no SQL server here to test.
– user28595
@Diegof I already managed to solve the problem, I used a Netbeans wizard to create the file.
– gato