Solved

Java variable arguments on constructor

Posted on 2009-07-08
10
382 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 73
unix in java example 9 53
Spring Framework HTTPSession management 1 23
couple of eclipse 5 21
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

910 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