Solved

Java variable arguments on constructor

Posted on 2009-07-08
10
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 60

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 60

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 60

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 60

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 60

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

695 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