no meu main tem isso:
EntityManagerFactory objfactory = Persistence.createEntityManagerFactory(“Alga2PU”);
e o erro eh esse:
Exception in thread “main” javax.persistence.PersistenceException: No Persistence provider for EntityManager named Alga2PU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at alga2.Alga2.main(Alga2.java:27)
C:\Users\valdemir\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
FALHA NA CONSTRUÇÃO (tempo total: 0 segundos)
Ainda não seguiu o tutorial?
segui mas usando o netbeans. mas da o mesmo erro
Então não seguiu. Ou se quer usar Netbeans procura um tutorial explicando no Netbeans.
pelo jeito o pessoal nao vai poder me ajudar… nao tenho outr opcao… vou voltar um degrau e reler os materiais sobre JPA… pois eu acho que o erro é em relacao ao JPA e nao ao hibernate…
Exception in thread “main” javax.persistence.PersistenceException: No Persistence provider for EntityManager named Alga2PU
Sera que alguem vai ajudar???
Já está usando o Eclipse ou perdendo tempo ainda com Netbeans?
Emerzoom
Fevereiro 28, 2018, 11:06am
#30
Bom dia a todos!
Cara, não tem erro. Eu até fiz um projeto novo aqui do zero, no Eclipse Luna, com Hibernate 5.2, JPA 2.0 e funcionou certinho.
Eu vou tentar te mostrar o que eu fiz com um exemplo até não muito inteligível, mas, vc tenta aí. Se não rolar, faz um descarrego, um despacho, uma missa, um culto, ritual, seja lá qual for sua crença ou credo, pq, cara, não tem erro!
<!-- 1. Persistence.xml: -->
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="simplejpa-pu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- Annotated entity classes -->
<class>com.simple.entity.Student</class>
<class>com.simple.entity.Course</class>
<!-- Config props -->
<properties>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/simplejpa" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="*****" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.flushMode" value="FLUSH_AUTO" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" /> <!-- Show SQL in console -->
<property name="hibernate.format_sql" value="true" /> <!-- Show SQL formatted -->
</properties>
</persistence-unit>
</persistence>
Classe Course
package com.simple.entity;
import java.io.Serializable;
import java.sql.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "course")
public class Course implements Serializable {
/**
*
*/
private static final long serialVersionUID = -9071942957966778145L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id")
private Long id;
@Column(name="name")
private String name;
@Column(name="startDate")
private Date startDate;
@Column(name="endDate")
private Date endDate;
public Course() {
// TODO Auto-generated constructor stub
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
@Override
public String toString() {
return "Course [id=" + id + ", name=" + name + ", startDate=" + startDate + ", endDate=" + endDate + "]";
}
}
Classe Student
package com.simple.entity;
import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
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 = "student")
public class Student implements Serializable {
/**
*
*/
private static final long serialVersionUID = 2142125727900505238L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id")
private Long id;
@Column(name="name")
private String name;
@Column(name="year")
private Date year;
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
private List<Course> courseList;
public Student() {
// TODO Auto-generated constructor stub
courseList = new ArrayList<Course>();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getYear() {
return year;
}
public void setYear(Date year) {
this.year = year;
}
public List<Course> getCourseList() {
return courseList;
}
public void setCourseList(List<Course> courseList) {
this.courseList = courseList;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", year=" + year + ", courseList=" + courseList
+ "]";
}
}
ConnectionFactory
package com.simple.dao.impl;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class ConnectionFactory {
private ConnectionFactory() {
// TODO Auto-generated constructor stub
}
public static EntityManagerFactory getInstance() {
return Persistence.createEntityManagerFactory("simplejpa-pu");
}
}
E ainda uma imagem do que está sendo utilizado de bibliotecas: