• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate Error using JPA

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

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 =
EntityManager em = emf.createEntityManager();
EntityTransaction et = em.getTransaction();
MessageWithAnnotations m = new MessageWithAnnotations("Jpa Persistence");
m.setNextMessage(new MessageWithAnnotations("Jpa Next Persistence"));
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

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

@Column(name = "MESSAGE_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;
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!