This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
Joined: Jul 05, 2001
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
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>