Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

MDM java API

Hi,

I am using the below code for searching in MDM repository. But I am getting null pointer exception.

ConnectionAccessor simpleConnection = null;

String connection = "servername";

//AuthenticateServerSessionCommand testAuthenticateUserSession;

RepositorySchema repositorySchema;

String session;

String repository = "repository name";

String str = "Table name";

String tabId;

int totalRecord;

DBMSType dbmsType = DBMSType.ORACLE;

RepositoryIdentifier repIdentifier;

RegionProperties regionProperties = new RegionProperties();

regionProperties.setLocale(Locale.ENGLISH);

regionProperties.setName("English US");

regionProperties.setRegionCode("engUSA");

wdComponentAPI.getMessageManager().reportSuccess("test1");

try {

simpleConnection = SimpleConnectionFactory.getInstance(connection);

repIdentifier = new RepositoryIdentifier(repository, connection, dbmsType);

RegionProperties dataRegion=regionProperties;

CreateUserSessionCommand createUserSessionCommand = new CreateUserSessionCommand(simpleConnection);

createUserSessionCommand.setRepositoryIdentifier(repIdentifier);

createUserSessionCommand.setDataRegion(dataRegion);

wdComponentAPI.getMessageManager().reportSuccess("test2");

try {

createUserSessionCommand.execute();

} catch (CommandException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

session = createUserSessionCommand.getUserSession();

AuthenticateUserSessionCommand authenticateUserSessionCmd = new AuthenticateUserSessionCommand(simpleConnection);

authenticateUserSessionCmd.setSession(session);

authenticateUserSessionCmd.setUserName("Admin");

authenticateUserSessionCmd.setUserPassword("");

try {

authenticateUserSessionCmd.execute();

} catch (CommandException e2) {

// TODO Auto-generated catch block

e2.printStackTrace();

}

GetRepositorySchemaCommand getRepositorySchemaCommand = new GetRepositorySchemaCommand(simpleConnection);

getRepositorySchemaCommand.setSession(session);

try {

getRepositorySchemaCommand.execute();

} catch (CommandException e3) {

// TODO Auto-generated catch block

e3.printStackTrace();

}

repositorySchema = getRepositorySchemaCommand.getRepositorySchema();

TableId tableId= repositorySchema.getTable("Products").getId();

FieldId[] fields = new FieldId[2];

fields[0] = repositorySchema.getFieldId("Products", "Name");

fields[1] = repositorySchema.getFieldId("Products", "Father's Name");

FieldSearchDimension fieldSearchDimension = new FieldSearchDimension(fields[1]);

TextSearchConstraint textSearchConstraint = new TextSearchConstraint("john", TextSearchConstraint.EQUALS);

FieldSearchDimension fieldSearchDimension1 = new FieldSearchDimension(fields[0]);

TextSearchConstraint textSearchConstraint1 = new TextSearchConstraint("test", TextSearchConstraint.EQUALS);

Search search = new Search(tableId);

search.addSearchItem(fieldSearchDimension, textSearchConstraint);

search.addSearchItem(fieldSearchDimension1, textSearchConstraint1);

ResultDefinition rd = new ResultDefinition(tableId);

rd.setSelectFields(fields);

RetrieveLimitedRecordsCommand retrieveLimitedRecordsCommand = new RetrieveLimitedRecordsCommand(simpleConnection);

retrieveLimitedRecordsCommand.setSession(authenticateUserSessionCmd.getSession());

retrieveLimitedRecordsCommand.setResultDefinition(rd);

retrieveLimitedRecordsCommand.setSearch(search);

try {

retrieveLimitedRecordsCommand.execute();

} catch (CommandException e4) {

// TODO Auto-generated catch block

e4.printStackTrace();

}

totalRecord = retrieveLimitedRecordsCommand.getRecords().getCount();

wdComponentAPI.getMessageManager().reportSuccess("records are"+totalRecord);

RecordResultSet records=retrieveLimitedRecordsCommand.getRecords();

for(int i=0; i<records.getCount(); i++)

{

Record record = records.getRecord(i);

//wdComponentAPI.getMessageManager().reportSuccess(""+record.getDisplayValue());

//System.out.println(record.getDisplayValue());

}

} catch (ConnectionException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

And the error i am getting is

java.lang.NullPointerException

at com.sap.mdm.internal.SessionConvertHelper.convertToLong(SessionConvertHelper.java:11)

at com.sap.mdm.commands.AuthenticateUserSessionCommand.execute(AuthenticateUserSessionCommand.java:62)

at com.sap.search.SearchView.onActionsubmit(SearchView.java:304)

at com.sap.search.wdp.InternalSearchView.wdInvokeEventHandler(InternalSearchView.java:160)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.doHandleActionEvent(WindowPhaseModel.java:420)

at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.processRequest(WindowPhaseModel.java:132)

at com.sap.tc.webdynpro.clientserver.window.WebDynproWindow.processRequest(WebDynproWindow.java:335)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:143)

at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doProcessing(ApplicationSession.java:319)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessingStandalone(ClientSession.java:713)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessing(ClientSession.java:666)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doProcessing(ClientSession.java:250)

at com.sap.tc.webdynpro.clientserver.session.RequestManager.doProcessing(RequestManager.java:149)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:62)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:53)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:386)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:364)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:1039)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:265)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:102)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:172)

Kindly suggest.

Former Member
Not what you were looking for? View more on this topic or Ask a question