• 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

EJB and Database

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
We are developing a web based application in EJB. I've a query for u all.Please help me out.
If in a database(Oracle 8i) I'm creating a sequence for the primary key.Since it is a sequence written in Oracle.Can I access the sequence from my entity bean.
But if I want to make this field as the bean managed field(Entity Bean). Is it possible?.If yes How the create method in my home interface look like? Generally while accessing the sequence we use sequencename.nextValue() in a servlet. But how it is to be done in EJB since it is a Primary Key. Is it possible to have sequence as the Primary Key?
Thanx
Mahesh
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible to have a sequence as a primary key value. you need to get the value of the sequence BEFORE you insert the entity bean into the database. try using "select seq.nextval from dual" to get the next value of the sequence, put that into a variable in your ejb and then use that in the insert statement in your ejbCreate method.
j
 
Mahesh Kulkarni
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx jon,
I'll try it. But before calling the seq.nextvalue from dual I've to make the connection with the database.That's OK.
One more query is that if I've Composite keys as Primary keys then How to access the same?
Thanx
Mahesh
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Typically a composite key would not be an autogenerated sequence, the two / more values are derived from somewhere else. In theory you should know these derived values - otherwise why is the entity being created. (IE if it is a bridging entity you should know the other entities it is bridging, and hence ask them for their portions of the composite key)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic