Link to home
Start Free TrialLog in
Avatar of Nargzul
Nargzul

asked on

Java variable arguments on constructor

I've view this:

http://today.java.net/pub/a/today/2004/04/19/varargs.html

I've try to do this on a constructor, but when I call it, I've this error:

java.lang.NoSuchMethodException: datamodel.DealProposition.<init>(datamodel.Deal, datamodel.Deal)

I must have this because: I can give a collection/array/... as parameter(JPQL new object), and the number can have many variation(2-100)
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

What is the code you have?
Avatar of Nargzul
Nargzul

ASKER


public class DealProposition {
    public Deal[] dealPropList;
        
    DealProposition(datamodel.Deal[] dllist){//I've try datamodel.Deal... dllist Too
 
        dealPropList = dllist;
    }
}

Open in new window

That constructor is not marked as public for one, but I will take a look if anything else.
Avatar of Nargzul

ASKER

It does the same with public declaration.

I've the impression that is JPQL that dosn't know how to gives parameter like this.
Try like this:
public class DealProposition {
	public Deal[] dealPropList;
 
	public DealProposition(Deal ... dllist) {
		dealPropList = dllist;
	}
}

Open in new window

A simple array should have worked though, even if you are not using the variable parameter construct (...).  Or possible you will need to do like this since JPQL.
public class DealProposition {
        private Deal[] dealPropList;
 
        public DealProposition() {
            super();
        }
 
        public void setDealPropList(Deal[] dllist) {
            this.dealPropList = dllist;
        }
 
        public Deal[] getDealPropList() {
            return this.dealPropList;
        }
}

Open in new window

Avatar of Nargzul

ASKER

(http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/jpa_langref.html ) for one good doc on JPQL.

Here is the example request:

SELECT NEW com.company.PublisherInfo(pub.id, pub.revenue, mag.price)
    FROM Publisher pub JOIN pub.magazines mag WHERE mag.price > 5.00

And they say every times it's a constructor expression, so I don't think it must have getters and setter.
Avatar of Nargzul

ASKER

Sorry I don't have see your previous message, I just try it now and it doesn't works
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nargzul

ASKER

A little dirty