• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Error using JPA

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic