aspose file tools*
The moose likes Object Relational Mapping and the fly likes jpa is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "jpa is not working" Watch "jpa is not working" New topic
Author

jpa is not working

pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213
i found this code for jpa.



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?)

thanks in advance.


:d
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213
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.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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.

http://download-east.oracle.com/docs/cd/B32110_01/web.1013/b28221/cfgdepds005.htm

Good Luck

Mark
[ December 31, 2007: Message edited by: Mark Spritzler ]
pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213

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
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
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)?

thanks.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

What I am trying to say is that
"persistence/LogicalName" is your EntityManager in jndi. However, you EntityManager is not called LogicalName.

Mark
pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213
"persistence/LogicalName" is your EntityManager in jndi. However, you EntityManager is not called LogicalName.


what does this mean?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

All I am saying is that

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.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jpa is not working