after getting entity manager, we can call, find(), remove(), persist() etc methods to perform database operations.
but i have 3 doubts here:
1. what is java:comp/env here? where it is declared?
2. what is persistence/LogicalName here? where it is declared?
3. how it is knowing on which database i am performing this operations? (i mean to say, in jdbc we specify driver name, database name, username and password, here we are not specifying anything, how it is working?)
You are looking at sample code, so LogicalName is not what you called your persistence unit/entity manager. LogicalName is there as something that you replace with your specific data. The sample can;t guess what you are going to call it.
Your persistence.xml is missing a bunch of stuff, where do you put your database connection information?
Try reading the Toplink docs here for what you put into the persistence.xml and what everything means.
EntityManager em = (EntityManager) ctx.lookup("persistence/LogicalName");
Means that there is an entity manager that is in JNDI under the "section" "persistence" with the name "LogicalName" in whoevers code that is. It is probably not the same name as your entity manager that is in JNDI.
Unless this is your code at your company, and if it is, then is that the correct persistence.xml, or is there another one, is there some other config file, or is there somewhere else in code that is binding that entity manager into jndi.
If you are using EJB3, also, you wouldn't even need that line of code, you could have the container inject the EntityManager in for you.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com