I have a complete Java EE web application with presentation layer and database. I use 3.1 chip glass derby and JPA to handle the stubbornness. I created a “Read” message, but now I have a troulbe doing Create and saved to the database. I think I'm close, but something is wrong with the way I'm trying to create.
Here is my EAO code:
@Stateless @LocalBean public class XRSSeao { @PersistenceContext EntityManager em; public XRSSeao() {} public void addEvent(String update){ Feed feed = new Feed(); feed.setStatus(update); feed.setId(2); em.getTransaction().begin(); em.persist(feed); em.flush(); em.clear(); em.getTransaction().commit(); } }
It will be called from another EJB. I also do not want to set the identifier, since this is the primary key that I want to create when I call the persist method. The error I get when I check:
"Caused by: java.lang.IllegalStateException: Exception Description: EntityTransaction cannot be used when using JTA.
If you don’t know what the problem is with this code, but you can provide an example of a simple save with an auto-generated primary key that would be just as useful.
This is my reading method that works:
public String lastUpdate(){ String resultString; Query q = em.createQuery("SELECT x FROM Feed x WHERE x.id = 1"); List<Feed> ListofStatus = q.getResultList();
}
If I do not need to use Transaction (), I have not found an example on the Internet that does not use it to create.
java java-ee jpa persistence jpql
Randnum
source share