Casting inheritance class in instance
Hi All..
my question is almost same as the question in this post:
http://forum.java.sun.com/thread.jspa?threadID=545767&messageID=2655556
in the post, charlie2086 ask how to access method in class ComputerPlayer when play declared as:
Player play = new ComputerPlayer();jsalonen answer with 3 solutions:
1) Declare the method in the Player class
2) Declare play as ComputerPlayer rather than Player
3) Cast play to ComputerPlayer before accessing the method. It is:
((ComputerPlayer)play).theMethod();But however, i would like to ask, is it possible to cast the inheritance class? what i mean is, play declared as:
Player play = new ComputerPlayer();and apply a 1 time casting in the instance, so that each time will no need to apply:
((ComputerPlayer)play).theMethod();when access methods in class ComputerPlayer
Thx or ur all helps..
But however, i would like to ask, is it possible to
cast the inheritance class? what i mean is, play
declared as:
Player play = new ComputerPlayer();
and apply a 1 time casting in the instance, so that
each time will no need to apply:
((ComputerPlayer)play).theMethod();when access methods in class ComputerPlayer
Oh yes, you could do that, but you will have to it in a variable like this
ComputerPlayer cPlayer = ((ComputerPlayer)play) ;
//now use cPlayer variable to access methods in class ComputerPlayer
play has been declared as type 'Player' . So if u want 2 use the 'play' variable, then ofcourse you will have 2 cast it each time.
however, if u r class has been properly designed, u could, using play access all methods of ComputerPlayer (either inherited from Player or overridden in ComputerPlayer), except those methods defined exclusively by ComputerPlayer (i.e not inherited from Player).
tx,
ram.
Similar Messages
-
Use CAST to check if an instance belongs to inherited classes.
Dear all.
I have got a method called GET_LINKS which is supposed to give back all references in an internal table which are of a given class or belong to classes being inherited.
( I do not have both - access to the internet and our R3 at once that is why I only provide pseudo code)
Example:
think of follwing structure:
cl_object
cl_class1
cl_class11
cl_class2
cl_class21
cl_class22
so if check against cl_objets the method should give back all references .... if cl_class1 only those who belongs to cl_class1 or class11...you got the idea.
so My method looks somewhat like following.
method get_links.
* changing ch_instance type ref to object.
* returnning re_links (table of instances)
loop at ait_links into lwa_links.
catch system-exception - move_cast_error
ch_instance ?= lwa_links-instance.
endcatch.
if sy-subrc is initial.
insert lwa_links into table re_links.
endif.
endloop.
endmethod.
coding works fine so far - the only thing I do not like is that I have to provide a changing parameter for the cast. I would prefer a local copy of an importing parameter for the checks.
But as soon as I use a very generic type declaration - like ref to object - no casting error will take place and I am not able to differentiate the groups down the inheritance.
I tried to create a dynamic reference variable but failed. I guess I would need to create a type dynamically but this is not possible before 6.4 (and I am on 4.6c)
Any suggestion for that?
Thank you very much.
ChristianHi, list my suggestion as following:
'ch_instance type ref to object'
As it is defined as an object type,
'ch_instance ?= lwa_links-instance.' won't catch any error, because OBJECT is the root type of any object type, if you only need to compare them and differentiate the class and inherited class from others, you can do like this:
catch system-exception - move_cast_error
lwa_links-instance ?= ch_instance.
endcatch.
By the way, I don't know what's the definition of lwa_links-instance is. I wrote some sample code for you scenario, as list it as following:
* I create two inherited class
CLASS C1 DEFINITION INHERITING FROM CL_ABAP_TYPEDESCR.
PUBLIC SECTION.
DATA: C1 TYPE C.
ENDCLASS.
CLASS C2 DEFINITION INHERITING FROM CL_GUI_CONTROL.
PUBLIC SECTION.
DATA: C2 TYPE C.
METHODS CONSTRUCTOR.
ENDCLASS.
CLASS C2 IMPLEMENTATION.
METHOD CONSTRUCTOR.
CALL METHOD SUPER->CONSTRUCTOR EXPORTING NAME = 'aaa'.
ENDMETHOD.
ENDCLASS.
* assume that you have a class, using CL_ABAP_CLASSDESCR
* we can get the name of it
DATA:
descr_ref TYPE ref to CL_ABAP_CLASSDESCR.
descr_ref ?= cl_abap_typedescr=>DESCRIBE_BY_OBJECT_REF( CLass ).
* then we can transfer the class name into the module get_links
module XXXX.
DATA: A TYPE REF TO C1,
B TYPE REF TO C2,
R TYPE REF TO OBJECT.
CREATE OBJECT A.
CREATE OBJECT R TYPE ('C1').
* here it goes well
* as the A type is C1, and R is create as C1 too
CATCH SYSTEM-EXCEPTIONS MOVE_CAST_ERROR = 1.
A ?= R.
ENDCATCH.
CREATE OBJECT R TYPE ('C2').
* here it can catch the error
* as the A type is C1, and R is create as C2, C1 & C2 has
* no relation like inherit
CATCH SYSTEM-EXCEPTIONS MOVE_CAST_ERROR = 1.
A ?= R.
ENDCATCH.
* XXXX is the class name which transfered into module
CREATE OBJECT R TYPE ('XXXX').
* then try to create the class according to class name
* which is you want
CATCH SYSTEM-EXCEPTIONS MOVE_CAST_ERROR = 1.
A ?= R.
ENDCATCH.
Hope my reply can help you solve the problem
By the way, the code cost me some time, so don't forget the reward points
thanks a lot -
Casting & abstract class & final method
what is casting abstract class & final method in ABAP Objects give some scenario where actually use these.
Hi Sri,
I'm not sure we can be any more clear.
An Abstract class can not be instantiated. It can only be used as the superclass for it's subclasses. In other words it <b>can only be inherited</b>.
A Final class cannot be the superclass for a subclass. In other words <b>it cannot be inherited.</b>
I recommend the book <a href="http://www.sappress.com/product.cfm?account=&product=H1934">ABAP Objects: ABAP Programming in SAP NetWeaver</a>
Cheers
Graham -
Casting timezone class object to Simpletimezone class object
When i try to cast timezone class object to a simpletimezone object it throws "java.lang.classcastexception" when i use J2re 1.4.2_06 while in J2re1.3 it works fine .
I am unable to understand this , can anybody help me out in this regard.
thanks
LokeshI agree with all
but try this out
SimpleTimeZone stz = (SimpleTimeZone)
ne) TimeZone.getTimeZone(id);Nothing in the specification says that
TimeZone.getTimeZone(id) returns an object that is a
SimpleTimeZone only that it is a TimeZone. It might
happen to also be a SimpleTimeZone but nothing in the
specifications says that it is.
Above statement throws classcast exception in
in jre1.4.2 but not in Jre1.3 and lower versions
........ remember TimeZone is base class and
SimpleTimeZone is sub class.If this is correct then in 1.3 it just happens to
return SimpleTimeZone object but nothing in the spec
says you can rely on this. You are relying on an
undocumented feature! Always a bad idea.
So wht has changed in the 2 runtimeenvironments.
Retorical?Hi,
sabre150 thanx a lot , u are right in earlier versions TimeZone.getTimeZone(id) was returning SimpleTimeZone object but in J2re 1.4.2 it returns sun.util.calendar.ZoneInfo object and hence the class cast exception was happening.
AND BELLYRIPPER , u were theoretically right , i was asking something that was happening in practical , so u better try out things and then come up with reasoning rather than just repeating theoretical things and expecting others to accept them blindly.
Anyway thanx a lot for the help. -
How can i have a refrence of a java class object instance in my c++ project
Hi!
How can i have a refrence of a java class object instance in my c++ project. Is there a way?hahaxia wrote:
The second question is the big one. The first question is half of the problem of "c++ to java" invocation and access. But the other half which is "java to c++ " invocation and access is still not solved. jni only provide the "java to c++ " DLL invocation Wrong,
Using JNI your java classes can have methods implemented in C/C++.
Using JNI you can call java classes.
There is no other possible interaction between C++ and java, so it does it all. -
Cast from Class A to Class A B should be allowed?
https://bugs.eclipse.org/bugs/show_bug.cgi?id=99107
public final class A<B> {
void doit() {
Class<A> clazz1 = (Class<A>) this.getClass();
Class<A<B>> clazz2 = (Class<A<B>>) clazz1;
clazz2.getName();
}Sun's javac (1.5.0_03) gives an error:
A.java:5: inconvertible types
found : java.lang.Class<A>
required: java.lang.Class<A<B>>
Class<A<B>> clazz2 = (Class<A<B>>) clazz1;
^------- Additional Comment #1 From Philippe Mulet 2005-06-09 06:11 [reply] -------
According to the spec, cast conversion is allowed since the types are not
probably distinct.
I thus believe this is a bug in javac.You can get around this with a double cast.
Class<A<B>> clazz2 = (Class<A<B>>) (Class) clazz1
Ugly, but it compiles. :(Or simply:
Class<A<B>> clazz2 = (Class) clazz1However, I suspect that the OP wasn't really looking
for a work around ;-) I have noted the problem and
will file a javac bug if it isn't a dupe. -
Alright, so I'm supposed to write an inheritance class called MusicStore, which is inherited from the Store ( already written), and then the MusicStore method tests out the MusicStore. The MusicStore has the additional attributes of the number of titles it offers and the its address...The store already offers the name of the store where the titles are located...I believe I'm writing it the MusicStore correctly, but I get this really odd error when I compile...I am not quite sure how it happens????? Helllpppp!!! I would appreciate it
I will post the error and the error is located a bit lower in the MusicStore that I posted-
"File: E:\comp 150\H10\MusicStore.java [line: 13]
Error: E:\comp 150\H10\MusicStore.java:13: cannot find symbol
symbol : constructor Store()
location: class Store"
Here is the Store:
/* Store Class
Anderson, Franceschi
public class Store
public final double SALES_TAX_RATE = 0.06;
private String name;
public Store( String newName )
setName( newName );
public String getName( )
return this.name;
public void setName( String newName )
this.name = newName;
public String toString( )
return( "name: " + this.name );
public boolean equals( Store otherStore )
return ( this.name.equalsIgnoreCase( otherStore.name ) );
}Here is the MusicStore:
/* MusicStore class
Smith, Tahnee
public class MusicStore extends Store
public final int DEFAULT_NUMBER = 0;
private int numberOfTitles;
public final String DEFAULT_ADDRESS = " ";
private String address;
public MusicStore()
{ // LINE 13 : Here is where the error is...I don't understand what is going on here.
address = DEFAULT_ADDRESS;
numberOfTitles = DEFAULT_NUMBER;
public MusicStore(String startNameStore, int startNumber, String startAddress)
super( startNameStore );
setNumberOfTitles( startNumber );
setAddress( startAddress);
public void setAddress( String newAddress)
address = newAddress;
public void setNumberOfTitles(int newNumber)
if ( numberOfTitles > 0 )
numberOfTitles = newNumber;
else
System.out.println(" Number of titles cannot be negative");
public String toString()
return super.toString()
+ " The number of titles are " + numberOfTitles
+ " The address is " + address;
}Here is the MusicStoreClient:
/* MusicStoreClient class
Anderson, Franceschi
public class MusicStoreClient
public static void main( String [] args )
MusicStore ms1 = new MusicStore( "Records, Inc.", 1000, "123 Elm Street" );
MusicStore ms2 = new MusicStore( "All Records Unlimited", 1200, "999 Green Street" );
System.out.println( ms1 );
System.out.println( ms2 );
ms2.setNumberOfTitles( 1000 );
ms2.setAddress( "123 Elm Street" );
if ( ms1.equals( ms2 ) )
System.out.println( "ms1 and ms2 are equal" );
else
System.out.println( "ms1 and ms2 are not equal" );
ms2.setName( "Records, Inc." );
if ( ms1.equals( ms2 ) )
System.out.println( "ms1 and ms2 are now equal" );
else
System.out.println( "ms1 and ms2 are still not equal" );
}Edited by: guitarlady3000 on Nov 5, 2008 4:22 PM
Edited by: guitarlady3000 on Nov 5, 2008 4:37 PMYou don't explicitly call the super(...) constructor in your parameterless MusicStore constructor code and so Java will automatically and behind the scenes place a call to super() there. Problem is, Store doesn't have a parameterless constructor. Solution: either give Store a parameterless constructor or explicitly call super with a proper parameter.
-
Trouble with instantiating inherited classes in a switch statement
Hi
I have few inherited classes which I need to instantiate in a switch statement based on command line argument supplied by user. I am ble to do that but I cannot access any methods once I come out of the switch scope. Please suggest a way to resolve this problem. The error I am getting is in the end of code in comments // //. Would really appreciate your help.
Thanks
Here is the code.
package assignment2;
import java.util.*;
import java.io.*;
abstract class Parent
abstract void childclassDescription();
void generalDescriptionToAllChilds()
System.out.println("general to all child classes");
childclassDescription();
class Child1 extends Parent
public void childclassDescription()
System.out.println("i'm child1");
class Child2 extends Parent
public void childclassDescription()
System.out.println("i'm child2");
class Child3 extends Parent
public void childclassDescription()
System.out.println("i'm child3");
public class Demo
public static void main(String[] args)
int option;
Parent p;
System.out.println("Pick from one of the following:");
option=1; // supplying
switch(option)
case 1:
p=new Child1();
break;
case 2:
p=new Child2();
break;
case 3:
p=new Child3();
default:
break;
p.generalDescriptionToAllChilds();
//error variable p might not have been initialized at line //
}Well I also think that in Java, it is possible for a reference type variable to refer to nothing at all. A reference that refers to nothing at all is called a null reference . By default, an uninitialized reference is null.
We can explicitly assign the null reference to a variable like this:
f = null;
But still i am not quety sure why you needed to do it. -
ClassCastexception when casting a Class that extends HttpServletRequestWrap
I have inherited some code that runs OK in JDK 1.4.2 in a JSP, but give s an exception when the JSP runs unfer 1.5.0. My Class is a as follows:
public class WrappedRequest extends HttpServletRequestWrapper {
public WrappedRequest(HttpServletRequest req) {
super(req);
/** Return value string of requested parameter.
* <ul>
* <li> If htmlEncode == NO_HTML_ENCODE, return the native request param, un-html encoded
* <li> If htmlEncode == HTML_ENCODE, return an html encoded copy of the requested parameter
* <li> If htmlEncode is neither, return the html encoded copy of the requested parameter
* </ul>
* @param name name of the request parameter
* @param htmlEncode whether html encoded/un-encoded parameter value should be returned.
* @return String of the requested parameter value. If parameter name is null, return null
public String getParameter(String name, int htmlEncode) {
if(name != null && (htmlEncode == NO_HTML_ENCODE)) {
String str = super.getParameter(name);
return str;
else
return getParameter(name);
public String getParameter(String name) {
String str = super.getParameter(name);
if(str != null)
str = Utils.htmlEncode(str); //Another package class
return str;
This class in normally invoked as follows:
String changeApproval = ((WrappedRequest)request).getParameter("CrApp" , WrappedRequest.NO_HTML_ENCODE);
I get a ClassCastException exception on this line. Any suggestions?
Regards,Stuart_Millington wrote:
Further to my original post I have another question. Please bear in mind that I am fairly new to Java and this is code that I have inherited. In the following line of code (which is the line that causes the exception:
String changeApproval = ((WrappedRequest)request).getParameter("CrApp" , WrappedRequest.NO_HTML_ENCODE);
Why is the request being cast? The following code SEEMS to run OK:
WrappedRequest wr = new WrappedRequest(request);
String CrApproval = wr.getParameter("CrApp" , WrappedRequest.NO_HTML_ENCODE);
Any ideas?
Regards,
Stuart MillingtonOkay, then I understand your problem.
You can only cast request to WrappedRequest when request IS A WrappedRequest - ie the statement request = new WrappedRequest(request) was called. You are apparently trying to convert a default implementation of HttpServletRequest into a WrappedRequest without first 'Wrapping' the request.
What does Wrapping a Request mean and do? A request object is generated by the servlet container and it isn't easy to switch in your own implementation. So instead you make a WrappedRequest which takes the original instance of the HttpServletRequest generated from by the container and adds functionality to it. A WrappedRequest would have to extend an HttpServletRequest, and implement all the public API of said parent class. Most of the time the methods would look something like this:
public String getParameter(String key) { return this.parentRequest.getParameter(key); } That is, it simply delegates most of the work to the HttpServletRequest it is wrapping. But some functions it may want to change behavior for and for those you insert your implementation.
What you need to do:
1) Learn how to use Java before you touch Servlets and server side stuff. You are adding too much complication by going straight to the end game. Use a book and the tutorials to get you through.
2) Take the time to run the JavaEE tutorial.
3) Start with your own code. Taking code snippets you see around the net and trying to get them to work is tough when you don't understand the concepts. For example, using a WrappedRequest is normally fairly useless if it isn't implemented using a Filter, and they work the best when they don't require a change to the request interface (i.e. when you never actually have to do a cast). Since you don't know Filters, and don't yet understand how the wrapper works I would suggest not using them.
This is probably a mis-use of the RequestWrapper idea anyway (since, like I said, it requires a change in interface). What you would be better off doing is simply choosing to pass the parameter through a utility function that does the encoding for you. Example like:
String changeApproval = HTMLEncoder.encode(request.getParameter("CrApp");when you want the parameter encoded and
String changeApproval = request.getParameter("CrApp");when you don't.
If you don't want to make your own utility for this purpose (and why would you) you can download a library that does it for you. One example is the [org.apache.commons.lang.StringEscapeUtils#escapeXML|http://commons.apache.org/lang/apidocs/org/apache/commons/lang/StringEscapeUtils.html#escapeXml(java.lang.String)] class#method from the Apache Foundation. The StringEscapeUtils is part of the Apache Commons Lang project, which you can reach [At the Commons/lang website.|http://commons.apache.org/lang/] -
ActiveX Object references - casting to a specific instance
I have some ActiveX controls that are used to interface between a vendors hardware. The activex controls are quite heavy weight in that at any one time there should only be one instance of each of the type of controls within the program.
What I want to do is keep the activex controls in the top level vi and pass references to sub-vi's in order to do property changes or method calls on the activex objects.
When I create an activex reference control in a sub vi it doesnt seem to know what methods/propertys are available on that reference. I beleive it needs casting/converting to a reference that will allow LabView to recognize the reference type but im not sure how to do this.
Thanks
TMCYour automation refnums are probably not linked to the ActiveX control. Try this... select a property node in your main VI's diagram that has the desired ActiveX control attributes displayed and then select Edit>>Create SubVI from the menu. The automation refnum in the subVI will be linked to the ActiveX control and will work the way you want it to. Copy this to your other subVIs and the property nodes will start behaving. The other way to link the automation refnums is to right-click on them and choose select ActiveX class and then browse to your control.
-Jim -
Inheritance, class indicator field and subclasses
Hi
Ok, I have an inheritance model with a base class (let's call it BaseClass), which is abstract. Every subclasse of BaseClass have a different implementation, but no additional attribute. I don't want to map all subclasses in Mapping Workbench, so I mapped BaseClass and configured inheritance to use a field as a class indicator (using the java class name).
Now, to read all subclasses in one single query, I do this:
Collection result = session.readAllObjects(BaseClass.class);
Now the problem is that TopLink generates the following SQL:
SELECT JAVA_CLASS_NAME, [...] FROM BASE_CLASS_TABLE WHERE JAVA_CLASS_NAME = 'com.[...].BaseClass'
Well, obviously this is not what I expected, since this will not return anything! I tried to use the "Read Subclasses on Query' option, to no avail. Am I missing something here? I thought this would pretty staight forward... :-(
TIA
Regards
Eric MorinYou must always map all subclasses that you wish to persist/read. If TopLink does not have a descriptor for a class it will persist/instantiate it as its superclass descriptor class.
If you explictly configured your descriptor to read subclasses on queries in code (descriptor.getInheritancePolicy().readSubclassesOnQueries()) it would generate the correct SQL that you want, however it would return you all instances of the root class, not the subclasses. The only way to read subclasses is to map them.
If you don't want to have to map all of the classes in the Mapping Workbench, you could just add the descriptor's for the subclasses in code.
i.e.
List allSublcasses = getAllMySubclasses();
for (Iterator iterator = allSublcasses.iterator(); iterator.hasNext(); ) {
Descriptor descriptor = new Descriptor();
Class subclass = (Class) iterator.next();
descriptor.setJavaClass(subclass);
descriptor.getInheritancePolicy().setParentClass(subclass.getSuperClass()); -
Access instance method of a class inside instance method of another class
Hi Friends
I have to use one c1->m1.
c1 is a public instantiation and m1 is a public Instance Method.
I called this m1 method by creating c1 object for class c1.
But problem is inise M1 method,i have a statement
CALL METHOD mo_central_person->if_hrbas_pd_object~read_infty.
here mo_central_person is of type some other class c2.
As without creating the object,i didn't use the above interface method.
Can please suggst me how to handle this.
Regards,
Sreeclass a definition.
public section.
methods : display,
disp.
data : a(10) type c value '10',
b(5) type c value 'abc'.
endclass.
class a implementation.
method display.
write : a.
endmethod.
method disp.
write : b.
endmethod.
endclass.
class b definition inheriting from a.
public section.
methods : display1.
data : c(7) type c value '7'.
endclass.
class b implementation.
method display1.
call method display( ).
write c.
endmethod.
endclass.
start-of-selection.
data : o_obj type ref to b.
create object o_obj.
call method o_obj->display1.
the method display is in class a.
we can call this method in class b using the following statement.
method display1.
call method display( ).
write c.
endmethod. -
Question about abstract classes and instances
I have just read about abstract classes and have learned that they cannot be instantiated.
I am doing some exercises and have done a class named "Person" and an abstract class named "Animal".
I want to create a method in "Person" that makes it possible to set more animals to Person objects.
So I wrote this method in class Person and compiled it and did not get any errors, but will this work later when I run the main-method?
public void addAnimal(Animal newAnimal)
animal.add(newAnimal);
}Is newAnimal not an instance?Roxxor wrote:
Ok, but why is it necessary with constructors in abstract classes if we don�t use them (because what I have understand, constructors are used to create objects)?Constructors don't create objects. The new operator creates objects. An object's c'tor is invoked after the object has already been created. The c'tors job is to initialize the newly-created object to a valid state. Whenever a child object is created, the parent's c'tor is run before the child's c'tor, so that by the time we're inside the child's c'tor, setting up the child's state, we know that the parent (or rather the "parent part" of the object we're initializing) is in a valid state.
Constructor rules:
1) Every class has at least one ctor.
1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
1.3) Constructors are not inherited.
2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed. -
Java Persistance: Question about query within inheritance class
In father class here is the annotation:
@Entity
@Table(name = "CONTENT_MEDIA")
@Inheritance(strategy=javax.persistence.InheritanceType.JOINED)
@DiscriminatorColumn(name="CONTENT_TYPE", discriminatorType=javax.persistence.DiscriminatorType.INTEGER)
@DiscriminatorValue("4")
In son class here is the annotation and query:
@Entity
@Table(name = "ISBN_BOOK")
@DiscriminatorValue("1000001")
@NamedQueries( {
@NamedQuery(name = "ISBN_BOOK.findViaISBN", query = "SELECT g FROM ISBNBook g WHERE g.ISBNnumber = :isbn")
When I do the query, the result is:
Internal Exception: org.apache.derby.client.am.SqlException: Comparisons between 'INTEGER' and 'CHAR' are not supported.Error Code: -1
Call:SELECT t0.CONTENT_ID, t0.CONTENT_TYPE, t0.OBTAIN_DATE, t0.SEARCH_TIMES, t0.LAST_SEARCH_DATE, t1.CONTENT_ID, t1.BOOK_NAME, t1.AUTHOR, t1.ISBN_NUMBER, t1.CURRENT_LOCATION FROM CONTENT_MEDIA t0, ISBN_BOOK t1 WHERE ((t1.ISBN_NUMBER = CAST (? AS VARCHAR(32672) )) AND ((t1.CONTENT_ID = t0.CONTENT_ID) AND (t0.CONTENT_TYPE = '1000001')))
bind => [AAA]
The problem is: t0.CONTENT_TYPE = '1000001'. I have set the column to Integer, why the JPA use the char?
Can anyone solve the problem for me?In father class here is the annotation:
@Entity
@Table(name = "CONTENT_MEDIA")
@Inheritance(strategy=javax.persistence.InheritanceType.JOINED)
@DiscriminatorColumn(name="CONTENT_TYPE", discriminatorType=javax.persistence.DiscriminatorType.INTEGER)
@DiscriminatorValue("4")In son class here is the annotation and query:
@Entity
@Table(name = "ISBN_BOOK")
@DiscriminatorValue("1000001")
@NamedQueries( {
@NamedQuery(name = "ISBN_BOOK.findViaISBN", query = "SELECT g FROM ISBNBook g WHERE g.ISBNnumber = :isbn")
})When I do the query, the result is:
Internal Exception: org.apache.derby.client.am.SqlException: Comparisons between 'INTEGER' and 'CHAR' are not supported.Error Code: -1
Call:SELECT t0.CONTENT_ID, t0.CONTENT_TYPE, t0.OBTAIN_DATE, t0.SEARCH_TIMES, t0.LAST_SEARCH_DATE, t1.CONTENT_ID, t1.BOOK_NAME, t1.AUTHOR, t1.ISBN_NUMBER, t1.CURRENT_LOCATION FROM CONTENT_MEDIA t0, ISBN_BOOK t1 WHERE ((t1.ISBN_NUMBER = CAST (? AS VARCHAR(32672) )) AND ((t1.CONTENT_ID = t0.CONTENT_ID) AND (t0.CONTENT_TYPE = '1000001')))
bind => [AAA]he problem is: t0.CONTENT_TYPE = '1000001'. I have set the column to Integer, why the JPA use the char?
Can anyone solve the problem for me?
I think now it is more readable.
(use code tags pls) -
NullPointerException at inheriting class with that has no MediaTracker ???
Hello everybody!
I have a very very strange problem and I am not able to understand and solve it..
This is it: I wrote two classes that inherit "scene" from the same superclass and are supposed to display an Icon and a button (They are MHP-Applications, but i guess it is more a java than a mhp problem, that's why I am posting to this forum..). The Icon class has a mediaTracker in it and works fine but the button class (with no mediaTracker) throws a NullPointerException when trying to access "scene" from the superclass. Why?? Has it something to do with the MediaTracker? I also found out that my icon class won't work too, when programming it without a Thread..Does anybody has an idea what is a possible reason for that?
The Icon class works well and is as follows:
public class Icon extends Scene implements Runnable{
public Icon() {
myWorkerThread = new Thread(this);
myWorkerThread.start();
public void display() {
MediaTracker tracker = new MediaTracker(this);
pic = Toolkit.getDefaultToolkit().getImage("AlphaGrafik.png");
tracker.addImage(pic, 0);
try{
tracker.waitForAll();
catch(InterruptedException e) {
hContainer1 = new HContainer(0,0,720,576);
icon = new HStaticIcon(pic, 0, 0, 720, 576);
hContainer1.add(icon);
//INHERITED FROM SUPERCLASS
scene.add(hContainer1);
scene.setVisible(true);
public void run() {
display();
This is my Button Class which throws the NullPointer:
public class MHPTest_1 extends Szene implements Runnable{
private Thread myWorkerThread;
private HContainer hContainer1;
private HTextButton button;
private Image pic;
public MHPTest_1() {
myWorkerThread = new Thread(this);
myWorkerThread.start();
public void display(){
hContainer1 = new HContainer(0,0,720,576);
button = new HTextButton();
button.setBounds(70, 80, 100, 50);
hContainer1.add(button);
//HERE I GET THE NULLPOINTEREXCEPTION!!!
scene.add(hContainer1);
scene.setVisible(true);
public void run() {
display();
Any help is very useful for me!
Thanks in advance,
with best regards,
Alex.Ups, yes it's a typo..
scene comes from the superclass Scene and is instantiated in a method there by
createScene(){
scene=factory.getBestScene(hst);
I solved it but now i have another problem with that "solution" which actually isn't one:
when i add
createScene();
to my Button Class and my Icon class,
they will work.
but if i want to add both my button class and my Icon class to my Superclass,
i create two instances of "scene", what is not allowed (it is a Digital TV App where only one instance of scene works..).
What's surprising here:
Sometimes it works with the IRT RI, sometimes it won't ???
What could be possible reasons for that?
I really need to add more like one Components (e.g. an Icon AND a button) to my scene instance, without creating two of them..
Do you have an idea of how to solve that?
As you see, i wasn't able to handle this yet ;-(
Maybe you are looking for
-
Query or script for calls with federated users
Hi all, Is there a query or script that can be run in SQL or Lync that gives us a report on calls between our Lync users and federated users?
-
Recently I can not open any app. in my Ipad except original ones. How can I fix this problem?
-
Variance between KE30 (COPA) Balance versus GL Balances (GR55)
Hi all, Would you know what are the main causes of the variances between COPA Report (KE30) versus GL Balance (GR55)? How to avoid it? I've been encountering this for the past months. How to resolve also the variances? Thank you in advance.
-
Hi, iMac 2013. I've successfully downloaded Yosemite, however when I've tried to install it, I got a message saying: "...cannot verify copy of Yosemite, download may be damaged, please download a new copy on the App Store", which I did once, and inst
-
Last Published vs Lsst Modified
Running PS 2010 with all correct patch/s and cu updates I need some clarity around the Last Published as opposed to the Last Modified, I have both fields coming through in the PWA and I'm trying to comprehend the logic as to why a Project is showin