GeeCON Prague 2014*
The moose likes EJB and other Java EE Technologies and the fly likes EJB and Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB and Database" Watch "EJB and Database" New topic
Author

EJB and Database

Mahesh Kulkarni
Ranch Hand

Joined: Jul 05, 2001
Posts: 62
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

Joined: Jul 04, 2001
Posts: 15
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

Joined: Jul 05, 2001
Posts: 62
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

Joined: Jul 14, 2001
Posts: 67
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)


The Eagle sneers at the Peacock<p>Systems Administrator<br />OrderWare Solutions Ltd<br /><a href="http://www.orderware.net" target="_blank" rel="nofollow">http://www.orderware.net</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EJB and Database