aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Servlet doesn't persist on db Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Servlet doesn Watch "Servlet doesn New topic
Author

Servlet doesn't persist on db

Enrico La Cava
Greenhorn

Joined: Nov 05, 2009
Posts: 4
Hi,

I'm new to JavaEE and I'm trying to write a servlet with a simple interface with MySQL. This servlet actually read the db without any problems but actually it doesn't write any change on db.
I've read the JavaEE tutorial but I cannot find useful thinghs about persistence in servlets.

My code is that:



The first two lines works properly because the value printed changes but the db remain unchanged.

This is the autogenerated code from NetBeans for the persist method:



but also a simple em.persist(object) doesn't work.

Can someone help me please? I use NetBeans with glassfish for develop.

Thanks in advance,

Enrico
Rj Salicco
Greenhorn

Joined: Apr 14, 2009
Posts: 17
What error, if any, are you getting? Can you post the code in which you are doing your select statement?


-RJ
http://www.rjsalicco.com
Enrico La Cava
Greenhorn

Joined: Nov 05, 2009
Posts: 4
Rj Salicco wrote:What error, if any, are you getting?


Actually NetBeans doesn't write any error.

Can you post the code in which you are doing your select statement?


I don't think I've understood. I use Java Persistence so I have an autogenerated Entity class with setter and getter for all field of my table. Netbeans wrote this class.

Now I've tryed to use JDBC instead of Java Persistence and it works fine. Anyone else can help me?

Thanks,

Enrico
Rj Salicco
Greenhorn

Joined: Apr 14, 2009
Posts: 17
Yes, JPA, understood. Just trying to see what Netbeans is generating for your entity and which JPA method you are calling to get the data into the instance of your entity.
Enrico La Cava
Greenhorn

Joined: Nov 05, 2009
Posts: 4
Rj Salicco wrote:Yes, JPA, understood. Just trying to see what Netbeans is generating for your entity and which JPA method you are calling to get the data into the instance of your entity.


Ok, this is the code:



Two examples of setter and getter:




This is another class (like the example of Java Tutorial) that create and interact with the entity manager:




Enrico La Cava
Greenhorn

Joined: Nov 05, 2009
Posts: 4
I don't know why my thread was moved...

Now I've try to create a new servlet, very very simple:



This is the error:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named FluidoDemoWebPU: Provider named org.hibernate.ejb.HibernatePersistence threw unexpected exception at create EntityManagerFactory:
javax.persistence.PersistenceException
javax.persistence.PersistenceException: [PersistenceUnit: FluidoDemoWebPU] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at biz.fluido.demo.dbTest.processRequest(dbTest.java:63)
at biz.fluido.demo.dbTest.doGet(dbTest.java:94)

This is my persistence.xml



The Assegni class is the same.

Rj Salicco
Greenhorn

Joined: Apr 14, 2009
Posts: 17
I think there may be a couple of paths to look into:

persistence.xml
- location? where is it in your app structure? META-INF?
- <class> </class> i think you need your class or package for your persistent entities declared here
- Hibernate; There may be some properties that need to be configured because you are specifically using the Hibernate provider.

Also, just something you may also want to do:
- extract your persistence calls to another class that you call from your Servlet.
- then you can write a unit test on that class to make sure the persistence is working.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet doesn't persist on db