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

jpa is not working

 
greenhorn
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
pooja jain
greenhorn
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"persistence/LogicalName" is your EntityManager in jndi. However, you EntityManager is not called LogicalName.



what does this mean?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic