Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Hibernate Error using JPA

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying the examples in the book Persistence with Hibernate and I am getting the following error.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named messages
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:41)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
.........


My code...

public boolean addMessage(MessageWithAnnotations message) {
EntityManagerFactory emf =
Persistence.createEntityManagerFactory(PERSISTENCE_CLASSES);
EntityManager em = emf.createEntityManager();
EntityTransaction et = em.getTransaction();
et.begin();
MessageWithAnnotations m = new MessageWithAnnotations("Jpa Persistence");
m.setNextMessage(new MessageWithAnnotations("Jpa Next Persistence"));
em.persist(m);
em.close();
emf.close();
return true;
}



I am not sure what is causing this. I have hibernate-entity manager in build path. I am using Eclipse to run this test. Please help.


Annnotated class


@Entity
@Table(name = "MESSAGES")
public class MessageWithAnnotations {

@Column(name = "MESSAGE_ID")
@GeneratedValue
@Id
private Integer id;

@Column(name = "MESSAGE_TEXT")
private String text;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "NEXT_MESSAGE_ID")
private MessageWithAnnotations nextMessage;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public MessageWithAnnotations getNextMessage() {
return nextMessage;
}

public void setNextMessage(MessageWithAnnotations nextMessage) {
this.nextMessage = nextMessage;
}

private MessageWithAnnotations() {}

public MessageWithAnnotations(String text) {
this.text = text;
}
}
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic