on 01-13-2006 5:54 PM
Hi all,
I have this business method into my EJB, than I'm using a web service in order to view the table records from a Web Dynpro. But I'm not able to see <i>result</i> array (see code). I think all is correct, have you got any idea on the possible cause? I'm sure that the data are retrived from this method. Thanks for your help.
/**
Business Method.
*/
public ModelBridge[] viewActiveModel() throws ModelException {
ArrayList modellings = new ArrayList();
try {
Collection active = modelHome.findByStatus(HelperClasses.STATUS_ACTIVE);
for (Iterator iterator = active.iterator(); iterator.hasNext();) {
modellings.add(getModelBridge((ModelloEntityLocal) iterator.next()));
}
} catch (FinderException e){
e.printStackTrace();
throw new ModelException(e.getMessage());
}
ModelBridge[] result = new ModelBridge[modellings.size()];
modellings.toArray(result);
return result;
}
Vito P.
Hi,
I guess it works if you write:
ModelBridge[] result = new ModelBridge[modellings.size()];
result = modellings.toArray(result);
return result;
or better
return (ModelBridge[] )modellings.toArray();
If you check the API of ArrayList.toArray(...) you will understand the cause of the problem.
Regards, Astrid
Message was edited by: Astrid Krause
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Astrid,
your solution generate an exception... it doesn't works.
public void viewActiveModel() {
try {
ActiveModelList = modelloSessionLocal.viewActiveModel();
}catch (
Exception e2
) {e2.printStackTrace();
}
}
-
-
public ModelBridge[] viewActiveModel() throws ModelException {
ArrayList modellings = new ArrayList();
try {
Collection active = modelHome.findByStatus(HelperClasses.STATUS_ACTIVE);
for (Iterator iterator = active.iterator(); iterator.hasNext();) {
modellings.add(getModelBridge((ModelloEntityLocal) iterator.next()));
}
} catch (FinderException e){
e.printStackTrace();
throw new ModelException(e.getMessage());
}
ModelBridge[] result = new ModelBridge[modellings.size()];
//Result è un array di Model Bridge che contiene tutti gli elementi dell'ArrayList
//modellings.toArray(result);
return (ModelBridge[] )modellings.toArray();
//return result;
}
Any ideas? thk.
Vito
I have two exception, the first is:
java.lang.ClassCastException, on this code:
public MyCommandBean() throws CreateException {
// looks up the session bean and creates the Home interface
try {
InitialContext ctx = new InitialContext();
home = (ModelloSessionLocalHome)ctx.lookup("localejbs/MySessionBean");
modelloSessionLocal = home.create();
} catch (Exception namingException) {
namingException.printStackTrace();
}
}
the second is java.lang.NullPointerException on this code:
public Collection viewAll() {
Collection bonuses = new ArrayList();
try {
Collection active = modelHome.findAll();
ModelloEntityLocal currModelloEntityLocal;
for (Iterator iterator = active.iterator(); iterator.hasNext();) {
currModelloEntityLocal = (ModelloEntityLocal) iterator.next();
if (currModelloEntityLocal!=null){
bonuses.add(getModelBridge(currModelloEntityLocal));
}
}
} catch (FinderException e) {
e.printStackTrace();
}
return bonuses;
hello vito,
could you post the whole codes?
for the exceptions:
> java.lang.ClassCastException, on this code:
home = (ModelloSessionLocalHome)ctx.lookup("localejbs/MySessionBean");
what is mapped as your localejbs/MySessionBean in the
descriptor?
> the second is java.lang.NullPointerException on this
> code:
Collection active = modelHome.findAll();
it is either your modelHome is null or the method
modelHome.findAll returned a null object. might be
caused by the prior exception.
regards
jo
Jo, consideration on these code lines:
<i>
private ModelloEntityLocalHome modelHome;
....
public Collection viewActiveModel() throws ModelException {
Collection bonuses = new ArrayList();
try {
Collection active = modelHome.findByStatus();
ModelloEntityLocal currBonusLocal;
for (Iterator iterator = active.iterator(); iterator.hasNext();) {
currBonusLocal = (ModelloEntityLocal) iterator.next();
if (currBonusLocal!=null){
bonuses.add(getModelBridge(currBonusLocal));
}
}
} catch (FinderException e) {
e.printStackTrace();
}
return bonuses;
}</i>
findByStatus method use the EJB QL statement: "select Object(b) from ModelloEntity b"
EntityBean are:
ModelloEntity
ModelloEntityBean
ModelloEntityHome
ModelloEntityLocal
ModelloEntityLocalHome
SessionBean are:
ModelloSession
ModelloSessionBean
ModelloSessionHome
ModelloSessionLocal
ModelloSessionLocalHome
What means that modelHome is null?
hello vito,
>What means that modelHome is null?
in your code:
try {
Collection active = modelHome.findAll();
ModelloEntityLocal currModelloEntityLocal;
for (Iterator iterator = active.iterator(); iterator.hasNext();) {
currModelloEntityLocal = (ModelloEntityLocal) iterator.next();
if (currModelloEntityLocal!=null){
bonuses.add(getModelBridge(currModelloEntityLocal));
}
}
} catch (FinderException e) {
e.printStackTrace();
}
there are only 2 places that will cause the
NullPointerException.
one is modelHome.findAll() method and second is
active.iterator().
however, this is assuming that the exception was
caught in this method and not inside other called
methods like getModelBridge.
jg
Hi Vito,
just a general remark:
- do you really need to work with EJBs and WSes just to get few records from a db to your WD app?
- starting with WD, i got the impression, i have to create web services for all data access, though i kind of back of from the idea to create my own DACBs (data access command beans)
- but creating DACBs is just some work and not difficult at all
Think about it.
Regards
Gregor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vito,
maybe there are attributes with "_" like "cust_id" in your ModelBridge class.
In my implementations this attributes doesn`t work with web services.
Karsten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hello vito,
i could see no problem with the coding...
try adding a check on you Collection instance
and see what you get.
<b>if(active.isEmpty())</b>
System.out.println("No data retrieved!");
regards
jo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.