• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

adding new record with em.persist(entity) is not working,

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone, I am having trouble to update and save new records. I am getting the following error when adding new record to the database.

javax.ejb.EJBException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'.


I think the problem might be due to Auto_incretment field that I have in the database.

any ideas please

thank you very much
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Have you used @NotNull annotation on auto generated Id field?

If so remove it. If problem further persist put your Entity bean code and table scheme here.

-Bajrang
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bajrang,

Thanks for the reply, I did solve the problem, it was due to the primary key which was not null as you said.

now I am having trouble with java.lang.NullPointerException . Basically I am trying to show data in a drop-down list. I thought you might be able to help me. when the following method is invoked, I get the error


 
Bajrang Asthana
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess supplierSessions.getSuppliers(); is returning the null list . Have you debuged your code?
Alternatively, You can also try the following-

Add one default select item into select item array like below-


then add the rest of items.

-Bajrang
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very very very much,

Yea, exactly, it was returning the null value, I shouldn't have placed that method in supplier session. I made another session, and placed the getSupplier method there, It is perfectly working now.

One thing else,

I have methods for update, create and delete, one thing I noticed that these method updates the database but not showing it. when I clean and build and re run the application, the changes can be seen.
I have session managed beans behind JSF and Stateless session beans in business layer. ANY IDEAS ?

and also, when I update the database, the form is not reset and I couldn't find any solutions for that, I guess there is something to do with the managed beans which I am not sure about. particularly, how to reset the form after updating the database.

Millions of thanks for your help. I appreciate it.
 
Bajrang Asthana
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you checked whether you are updating JSF view with new data that you have saved/ updated in database.
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yea, the data in the database gets updated, after clean and build, I can see the newly created or update in the browser.

Can you tell me, how to update the JSF page to retrieve the updated data from database.

Thanks
 
Bajrang Asthana
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is It possible for you to show code section what exactly you are doing?

However If you are updating the managed bean(that you are using on JSF page) with latest value then your change will be displayed there.
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Bajrang

I think I found the problem, I am showing the data from a VIEW, then getting this data trying to update the database tables related to the view. it is perfectly working and the database gets updated. but the View still showing the same data retrieved previously, I have a session scoped managed bean and the data is retrieved from view with the following method and passing the list to the JSF datatable.


the session bean is stateless and local. the for the session bean is like:


So, now I want to find a way to show the updated data in the page. the main problem here seems to be different between tables and View. tables are updated but the view show same data. but when you clean and build the application, the changes are displayed

I appreciate your help.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic