Solved

Java variable arguments on constructor

Posted on 2009-07-08
10
370 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
endX challenge 2 50
count11 challenge 6 47
parentbit challenge 3 52
json format text only 4 65
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now