• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

EntityManager.persist(obj) is not actually storing the object in Database

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am new to EJB.
I trying to store an Entity bean into Database using EntityManager.persist() method.
However I can see that object is not going into the database and no error or exception is shown on the console.
In contrast to this the same entity manager is deleting and updating the beans and working fine.
What may be the reason.

Below is part of my persistence.xml





The Entity bean as below






Please suggest.

Best Regards,
Rakesh
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A class to be a JPA Entitty it needs to have the @Id in it.
 
rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

If this is the case. Neither updates nor delete should be performed on the same.
However the same is being performed.
So now what may be the reason behing entity not getting persisted into the database.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rakesh kadulkar wrote:Hi,

If this is the case. Neither updates nor delete should be performed on the same.
However the same is being performed.
So now what may be the reason behing entity not getting persisted into the database.


Or maybe to merge it do not need a @Id.

I readed 3 books that says that it needs the @Id to a class to be considered an entity, maybe your provider do not need this for the update.
 
Ranch Hand
Posts: 100
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If persist is not working, I am not sure how the entities are present in the database to be updated or deleted. Are they being manually created by using some db connecting utility?
If so, I can think of one particular issue. In case of persist, the db has to know what value to use as Id/primary key. But if you manually insert entities in db with some random id, update or delte using that Id will not be an issue with the db since the id is already there.
May be you can use something like auto generation strategy for primary key and then try to persist the entities and see if that works.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe this posts will help: JPA TableGenerator – Simple Primay Key, JPA SequenceGenerator
 
rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,
Thanks for the replies.
I had been through the links that are provided. Those will be useful to me in the future.
But my problem is not yet resolved. Here below i am sharing the entire class and the id class





Your help in this regards is appreciated.
Best Regards,
Rakesh
 
rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

lokesh chenta wrote:If persist is not working, I am not sure how the entities are present in the database to be updated or deleted. Are they being manually created by using some db connecting utility?
If so, I can think of one particular issue. In case of persist, the db has to know what value to use as Id/primary key. But if you manually insert entities in db with some random id, update or delte using that Id will not be an issue with the db since the id is already there.
May be you can use something like auto generation strategy for primary key and then try to persist the entities and see if that works.



Yes you are write the records are already present in the database. They are inserted using the sql developer tool.
However the records are updated/deleted using EJB. And they are getting updated/deleted successfully.
However when i am inserting using EJB it is not getting inserted and further it does not shows any error in the logs.

I cannot use sequence/auto generation as I am suing composite primary key.
I have posted the structure beloe.
Please refer to it and suggest me what may be going wrong here.

Best Regards,
Rakesh
 
rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi any update on the same.
If I try to create a record manually and try to insert it into the database the record gets inserted successfully but I am getting an object from the database,
deleting it into the database and then updating the state of the object and then trying to persists the same object back into the database however i find that it does not gets inserted into the database. Please let me know what may be the error.

Regards,
Rakesh
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

...deleting it into the database and then updating the state of the object and then trying to persists the same object back into the database however i find that it does not gets inserted into the database.


Can you show the code for this?
 
rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The code is scattered all around and cannot be placed here.
There are multuple wrappers.
However if I use the same code to insert a fresh self created object into the database then it works.

Regards,
Rakesh
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The code is scattered all around and cannot be placed here.
There are multuple wrappers.


Then it might be something to do with session/transaction association of the object you are trying to save. Since you don't have anything in the logs (which seems strange), however it might worth adding some debug information around the code where you save this object and see?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic