Solved

Java variable arguments on constructor

Posted on 2009-07-08
10
388 Views
Last Modified: 2012-08-14
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)
0
Comment
Question by:Nargzul
  • 5
  • 5
10 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24807282
What is the code you have?
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24807366

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

Open in new window

0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24807581
That constructor is not marked as public for one, but I will take a look if anything else.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 1

Author Comment

by:Nargzul
ID: 24807611
It does the same with public declaration.

I've the impression that is JPQL that dosn't know how to gives parameter like this.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24807649
Try like this:
public class DealProposition {
	public Deal[] dealPropList;
 
	public DealProposition(Deal ... dllist) {
		dealPropList = dllist;
	}
}

Open in new window

0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24807697
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

0
 
LVL 1

Author Comment

by:Nargzul
ID: 24807757
(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.
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24807858
Sorry I don't have see your previous message, I just try it now and it doesn't works
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 24813472
Yeah, that must be something with JPQL and I haven't used that, so not sure how to resolve.  

You can try to request attention and get other experts in the Java area who may have experience with JPQL to help.

For workarounds, thoughts that come to mind:
+If SQL server you are connecting to supports XML, you can get your data as an xml string that can have 2 - 100 nodes which you then can parse out in the constructor which will then have one defined argument of type XML or String.
+Can concatenate your columns in SQL to be comma or otherwise delimited (i.e. SELECT Column1 + '||' + Column2 ...), then pass as a String to your constructor where you use the split method of String.
0
 
LVL 1

Author Closing Comment

by:Nargzul
ID: 31601278
A little dirty
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 52
Java Server Faces parameter pass? 6 48
Cipher Configuration on Apache HTTPD 4 62
custom annotations 9 38
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question