• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB QL help needed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using jboss.
I am using xdoclet to autogenerate the reqd intefaces.
My Entity bean reads as -
package helloworld;
/**
* @ejb.bean type="BMP"
* name="helloworld/BMPBean"
* jndi-name="helloworld/BMP"
* view-type="both"
* @ejb.pk generate = "true" class = "helloworld.BMPPK"
* @ejb:transaction type="Required"
* @jboss:table-name table-name="catagory"
* @jboss:create-table create="false"
* @jboss:remove-table create="false"
*/
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.ejb.RemoveException;
import javax.ejb.CreateException;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
public abstract class BMPBean implements EntityBean {
int catagoryId;
String name;
int parentId;
// Business methods
/**
* @ejb.persistent-field
* @ejb.interface-method
* @jboss:column-name CATAGORY_ID
* @ejb.interface-method view-type="both"
*/
public int getCatagoryId() {
return catagoryId;
}
/**
* @ejb.interface-method view-type="both"
*/
public void setCatagoryId(int vCatagoryId) {
catagoryId = vCatagoryId;
}
/**
* @ejb.persistent-field
* @ejb.interface-method
* @jboss:column-name NAME
* @ejb.interface-method view-type="both"
*/
public String getName() {
return name;
}
/**
* @ejb.interface-method view-type="both"
*/
public void setName(String vName) {
name = vName;
}
/**
* @ejb.persistent-field
* @ejb.interface-method
* @jboss:column-name PARENT_ID
* @ejb.interface-method view-type="both"
*/
public int getParentId() {
return parentId;
}
/**
* @ejb.interface-method view-type="both"
*/
public void setParentId(int vParentId) {
parentId = vParentId;
}
// Callback methods
/**
* Create Catagory.
*
* @ejb.create-method
*/
public void ejbCreate(int vCatagoryId, String vName, int vParentId) throws CreateException {
// Logic to insert value in to the database
Connection mConn = null;
try {
mConn = getConnection();
String mInsertSql = "INSERT INTO CATAGORY(CATAGORY_ID, NAME, PARENT_ID) VALUES(" + vCatagoryId + ", '" + vName + "', " + vParentId + ")";
Statement mStatement = mConn.createStatement();
mStatement.executeUpdate(mInsertSql);
}
catch (Exception vException){
System.out.println("Exception in ejbCreate()" + vException);
}
finally {
if (mConn != null){
try {
mConn.close();
}
catch (SQLException vSQLException){
System.out.println("Closing Conn exception " + vSQLException);
}
}
}
}
public void ejbPostCreate(int vCatagoryId, String vName, int vParentId) {
}
public void ejbRemove() throws RemoveException {
// Logic to delete the inserted record
System.out.println("Write Logic to delete the inserted record");
}
public int ejbFindByPrimaryKey(int vCatagoryId) {
Connection mConn = null;
try {
mConn = getConnection();
Statement mStatement = mConn.createStatement();
String mSql = "SELECT * FROM CATAGORY WHERE CATAGORY_ID=" + vCatagoryId;
ResultSet mResultSet = mStatement.executeQuery(mSql);
if (mResultSet.next()) {
System.out.println("In ejbFindByPrimaryKey() method");
System.out.println("Catagory Id is " + mResultSet.getString("CATAGORY_ID"));
System.out.println("Name is " + mResultSet.getString("NAME"));
System.out.println("Parent ID is " + mResultSet.getString("PARENT_ID"));
}
mResultSet = null;
return vCatagoryId; // FIX ME
}
catch (Exception vException) {
System.out.println("Exception in ejbFindByPrimaryKey()" + vException);
}
finally {
if (mConn != null){
try {
mConn.close();
}
catch (SQLException vSQLException){
System.out.println("Closing Conn exception " + vSQLException);
}
}
}
return 0;
}
public void ejbLoad() {
System.out.println("Write Logic to load the record");
}
public void ejbStore() {
System.out.println("Write Logic to store the record");
}

private Connection getConnection() {
try {
Context mContext = new InitialContext();
DataSource mDataSource = (DataSource) mContext.lookup("java racleDS");
return mDataSource.getConnection("matrix", "matrix");
}
catch (Exception vException) {
vException.printStackTrace();
}
return null;
}
}
When i deploy this bean the server gives me an error as -
Caused by: java.sql.SQLException: Column not found: ) in statement [CREATE TABLE
HELLOWORLD_BMP (CATAGORY_ID INTEGER NOT NULL, NAME VARCHAR(256), PARENT_ID INTE
GER NOT NULL, CONSTRAINT PK_HELLOWORLD_BMP PRIMARY KEY ())]
at org.hsqldb.Trace.getError(Trace.java:180)
at org.hsqldb.Result.<init>(Result.java:175)
at org.hsqldb.jdbcConnection.executeHSQL(jdbcConnection.java:907)
at org.hsqldb.jdbcConnection.execute(jdbcConnection.java:718)
at org.hsqldb.jdbcStatement.fetchResult(jdbcStatement.java:686)
at org.hsqldb.jdbcStatement.executeUpdate(jdbcStatement.java:85)
at org.jboss.resource.adapter.jdbc.local.LocalStatement.executeUpdate(Lo
calStatement.java:231)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStartCommand.createTable(JDBCStart

I have specified the table name as 'CATAGORY'. But why does the server create a new table by some awkward 'HELLOWORLD_BMP' ?
Please help.... :roll:
Janarthan S
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default JBoss will create tables for each of your CMPs when they are deployed. You can turn this off by editing the standardjbosscmp-jdbc.xml file. Set the create-table element to false.
 
reply
    Bookmark Topic Watch Topic
  • New Topic