I looked into how to configure the persistence.xml
file in a basic way, but I was even more confused about this configuration.
So, I'd like to know how I can do a basic configuration in the persistence.xml
file according to JPA and Hibernate to access a database no SQL Server 2008 ?
Information regarding 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 named tarefas
with the fields id int
, descricao VARCHAR(50)
, finalizado int
and data_finalizado DATETIME
.
Information regarding the structure of the project and the application:
I have already added all JARs for Hibernate and JPA and also the JDBC driver for SQL Server.
And the project structure looks like this:
...\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 annotations for the Framework. And the other packages do not contain classes yet.
Note:
The example application is for the desktop platform and the IDE I'm using and NetBeans.