Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB and Database

 
Mahesh Kulkarni
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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
 
jon boydell
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Karl Laird
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • 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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic