• 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

Servlet doesn't persist on db

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 20
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What error, if any, are you getting? Can you post the code in which you are doing your select statement?
 
Enrico La Cava
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
R.J. Salicco
Greenhorn
Posts: 20
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
R.J. Salicco
Greenhorn
Posts: 20
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic