Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send

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
+Pie Number of slices to send: Send
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


+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Have you checked whether you are updating JSF view with new data that you have saved/ updated in database.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
My pie came with a little toothpic holding up this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2449 times.
Similar Threads
character encoding from jsp->servlet
InputText Field - ValueChangeListener attribute
JPA UserTransaction Injection...
Database synchronization with Entity Bean
Display Question Message on JSF
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:15:08.