Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [RESOLVED] ClassCastException(ClassCastException com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to org.eclipse.persistence.jaxb.JAXBContext)
icon14.gif  [RESOLVED] ClassCastException [message #655595] Mon, 21 February 2011 16:22 Go to next message
Matthieu Lentwojt is currently offline Matthieu Lentwojt
Messages: 6
Registered: February 2011
Junior Member
Hello,

I'm trying to use EclipseLink to create a bridge between POJO and SDO DataObjects.

I followed the information at this page : http://wiki.eclipse.org/EclipseLink/Examples/SDO/JAXB

My code :
try {
			javax.xml.bind.JAXBContext jaxbContext = JAXBContext
					.newInstance(Note.class);
			JAXBHelperContext jaxbHelperContext = new JAXBHelperContext(
					jaxbContext);
			jaxbHelperContext.getXSDHelper().define(getStringXSD());

			Note poj = new Note();
			DataObject pojoDO = jaxbHelperContext.wrap(poj);

			System.out.println("POJO : " + poj);
			System.out.println("SDO  : " + pojoDO);
			
		} catch (JAXBException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}



The exception is throw by this line :
JAXBHelperContext jaxbHelperContext = new JAXBHelperContext(jaxbContext);


The exception is the following :
java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to org.eclipse.persistence.jaxb.JAXBContext
	at org.eclipse.persistence.sdo.helper.jaxb.JAXBHelperContext.<init>(JAXBHelperContext.java:122)
	at org.eclipse.persistence.sdo.helper.jaxb.JAXBHelperContext.<init>(JAXBHelperContext.java:111)
	at Test1.launchPOJOSDO(Test1.java:26)
	at Test1.main(Test1.java:17)



I used a clean Eclipse Environment, based on JRE 1.6.
I created the JAVA_HOME and the ECLIPSELINK_HOME.

I don't understand why this exception is thrown.

Do someone know why ?

Thx in advance, and excuse me for my bad english level.

[Updated on: Tue, 22 February 2011 13:09]

Report message to a moderator

Re: ClassCastException [message #655732 is a reply to message #655595] Tue, 22 February 2011 09:10 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise Doughan
Messages: 163
Registered: July 2009
Senior Member

You need to ensure that you specify EclipseLink MOXy as your JAXB provider. This is done by adding a file called jaxb.properties in the same package as your model classes with the following entry:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
Re: ClassCastException [message #655823 is a reply to message #655595] Tue, 22 February 2011 13:07 Go to previous messageGo to next message
Matthieu Lentwojt is currently offline Matthieu Lentwojt
Messages: 6
Registered: February 2011
Junior Member
That's it. It's work.

Thank you very much.

PROBLEM RESOLVED.
ClassCastException [message #716574 is a reply to message #655595] Wed, 17 August 2011 13:54 Go to previous message
chitti babu is currently offline chitti babu
Messages: 9
Registered: February 2011
Junior Member
Hi Please help me to solve this issue,

But i am using Eclipse , jdk 6, Jboss 5, Sporing message listener. Weblogic 11g is using to send messages . Getting messages from WL Queue to my app thru some logic.
I am able to print xml messages in the console, but getting exception before unmarshal this,

Code :
JAXBContext jc = JAXBContext.newInstance("com.bopeep.gen");
Unmarshaller unmarshaller = jc.createUnmarshaller();
// unmarshall into Classes from a File
bilgMsg = (BILGMSG) unmarshaller.unmarshal( new StreamSource( new StringReader(stringMessage)));

Please see the below error and help to resolve this
Exception:
11:41:49,475 WARN [DefaultMessageListenerContainer] Execution of JMS message listener failed, and no ErrorHandler has been set.
java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to javax.xml.bind.JAXBContext
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:149)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:285)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)

[Updated on: Wed, 24 August 2011 12:13]

Report message to a moderator

Previous Topic:Howto log SQL with java.util.logging?
Next Topic:PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources
Goto Forum:
  


Current Time: Sat Jul 26 05:25:11 EDT 2014

Powered by FUDForum. Page generated in 0.02275 seconds