Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • 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
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;
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic