Solved

Java variable arguments on constructor

Posted on 2009-07-08
10
400 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 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
MS Dynamics Made Instantly Simpler

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

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why my table column Id is not passed to java object? 4 46
tomcat administrtor 12 68
login form jsp example 2 55
Better way to make a string with template variables in java 3 34
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

730 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