wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes adding new record with em.persist(entity) is not working, Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "adding new record with em.persist(entity) is not working, " Watch "adding new record with em.persist(entity) is not working, " New topic
Author

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

Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
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
Bajrang Asthana
Ranch Hand

Joined: May 24, 2011
Posts: 32

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

Joined: Dec 16, 2010
Posts: 96
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

Joined: May 24, 2011
Posts: 32
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

Joined: Dec 16, 2010
Posts: 96
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

Joined: May 24, 2011
Posts: 32
Have you checked whether you are updating JSF view with new data that you have saved/ updated in database.
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
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

Joined: May 24, 2011
Posts: 32
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

Joined: Dec 16, 2010
Posts: 96
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding new record with em.persist(entity) is not working,