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?)
Originally posted by Mark Spritzler: 1. It is a standard, meaning it is in the spec. 2 and 3 are all in the persistence.xml file. in your META-INF directory.
Mark
thanks mark.
following is my persistence.xml file:
i dont see anywhere 'persistence/LogicalName' being mentioned.
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.
Mark [ December 31, 2007: Message edited by: Mark Spritzler ]
pooja jain
greenhorn
Ranch Hand
Joined: Jan 12, 2005
Posts: 213
posted
0
Your persistence.xml is missing a bunch of stuff, where do you put your database connection information?
but then how its working?
my question was actually how it is working?
pooja jain
greenhorn
Ranch Hand
Joined: Jan 12, 2005
Posts: 213
posted
0
thanks mark for the link but i didn't get anything out of it.
the persistence.xml file which i posted works perfectly at my end. but i want to understand in and out of it.
please help.
pooja jain
greenhorn
Ranch Hand
Joined: Jan 12, 2005
Posts: 213
posted
0
i get it where are we keeping this information (database name, username and password). its in configuration file of server. we are using datasource method of getting connection.
something like this:
but i am still unclear about 'persistence/LogicalName'.
also, how entity manager is knowing which persistence unit we are using as there is no relationship between entity manager and persistence unit (which knows about database)?
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.