Hi Matt,
I've successfully used JiBX with Hibernate in the past, so I'm not aware
of any problems in this area. It looks to me like what's going wrong in
this particular case is that the instance of UserImpl being passed in
for marshalling by JiBX has not been modified by Hibernate. I don't know
what would cause that to happen - different versions of UserImpl in your
classpath, perhaps, with one version not modified by Hibernate?
The reason I'm saying this is from the exception message. When you run
the JiBX binding compiler it generates code that converts your bound
classes to and from XML. Hibernate then does its own bytecode
modification, in which it modifies both your original code and the code
generated by JiBX. The ClassCastException is occurring when casting to a
Hibernate-generated class, which means it's a cast that was added by
Hibernate.
<rant>You'd think that by now someone at Sun would have figured out that
it'd be really useful to give the actual type of the object for a
ClassCastException (and not just the expected type). This is the sort of
thing that would be fixed in 1 minute with an open source version of
Java. And yes, I know that Sun claims to be moving in that direction -
but if they do release Java as open source it'll likely be under a
crippled license that makes it essentially worthless to the larger open
source community.</rant>
But now that I look at this in more detail, I wonder if there may be a
problem in using this type of structure with Hibernate - the
AbstractPieceImpl mapping says that Creator will always be a Producer
instance, and the Producer mapping uses the UserImpl mapping, but will
Hibernate modify the code so that Producer is an instance of
UserImpl$$EnhancerByCGLIB$ $4c56d3d? Your best bet to track down what's
going wrong is probably to set a breakpoint in the getCreator method and
see what is actually being returned, including the class hierarchy
actually implemented.
- Dennis
Dennis M. Sosnoski
SOA, Web Services, and XML
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-296-6194 - Wellington, NZ +64-4-298-6117
Matt MacDonald wrote:
Hi,
I'm a newbie to JIBX and I'm starting to prototype with it to see if
we can use it as our xml binding solution. All has worked well with
our object model until I ran a binding test using a Hibernate
generated object. I'm getting the following exception when marshalling:
java.lang.ClassCastException: org.prx.user.UserImpl$$EnhancerByCGLIB$
$4c56d3d
at org.prx.user.JiBX_piece_bindingProducer_access.marshal()
at org.prx.piece.AbstractPieceImpl.JiBX_piece_binding_marshal_2_3
(AbstractPieceImpl.java)
at org.prx.piece.PieceImpl.JiBX_piece_binding_marshal_3_2
(PieceImpl.java)
at org.prx.piece.JiBX_piece_bindingPieceImpl_access.marshal()
at org.prx.piece.PieceImpl.marshal(PieceImpl.java)
at org.jibx.runtime.impl.MarshallingContext.marshalRoot(Unknown
Source)
at
org.jibx.runtime.impl.MarshallingContext.marshalDocument(Unknown Source)
at org.prx.piece.PieceManagerTest.testGet5NewPieces
(PieceManagerTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit2.JUnitStarter.main
(JUnitStarter.java:32)
I read this post: http://www.mail-archive.com/jibx-
[EMAIL PROTECTED]/msg01042.html and changed all my mappings
over to use the get/set-method instead of fields but I am still
getting the exception above. Does it have to do with the abstract
mappings?
My mapping file is below and any help would be appreciated.
-thanks
-matt
<binding>
<namespace uri="http://www.prx.org" default="elements"/>
<!-- Piece Mapping -->
<mapping class="org.prx.piece.AbstractPieceImpl" abstract="true">
<value name="id" get-method="getId" set-method="setId"/>
<value name="title" get-method="getTitle" set-
method="setTitle"/>
<value name="createdDate" get-method="getCreateDate" set-
method="setCreateDate"/>
<structure get-method="getExtras" set-method="setExtras">
<value name="fullDescription" get-
method="getFullDescription" set-method="setFullDescription"/>
<value name="producers" get-method="getProducers" set-
method="setProducers"/>
</structure>
<structure get-method="getCreator" set-method="setCreator"
map-as="org.prx.user.Producer"/>
<structure get-method="getImage" set-method="setImage" map-
as="org.prx.dropbox.ImageFile"/>
<structure get-method="getLanguage" set-method="setLanguage"
map-as="org.prx.util.Language"/>
<collection name="adjectives" get-method="getAdjectives" set-
method="setAdjectives" type="java.util.TreeSet">
<structure type="org.prx.adjective.AdjectiveImpl"/>
</collection>
<collection name="topics" get-method="getTopics" set-
method="setTopics" type="java.util.HashSet">
<structure type="org.prx.piece.category.TopicCategory"/>
</collection>
<collection name="types" get-method="getTypes" set-
method="setTypes" type="java.util.HashSet">
<structure type="org.prx.piece.category.TypeCategory"/>
</collection>
</mapping>
<mapping name="piece" class="org.prx.piece.PieceImpl"
extends="org.prx.piece.AbstractPieceImpl">
<structure map-as="org.prx.piece.AbstractPieceImpl"/>
<value name="discount" get-method="getDiscount" set-
method="setDiscount"/>
<value name="runningTime" get-method="getRunningTime" set-
method="setRunningTime"/>
</mapping>
<!-- End Piece Mapping -->
<!-- Members -->
<mapping class="org.prx.user.MemberImpl" abstract="true">
<value name="id" get-method="getId" set-method="setId"/>
<value name="username" get-method="getUsername" set-
method="setUsername"/>
</mapping>
<mapping class="org.prx.user.UserImpl" abstract="true">
<structure map-as="org.prx.user.MemberImpl"/>
<value name="firstName" get-method="getFirstName" set-
method="setFirstName"/>
</mapping>
<mapping name="creator" class="org.prx.user.Producer"
extends="org.prx.user.UserImpl">
<structure map-as="org.prx.user.UserImpl"/>
</mapping>
<!-- End Member Mapping -->
<!-- Files -->
<mapping name="image" class="org.prx.dropbox.ImageFile">
<value name="url" get-method="getURL" set-method="setURL"/>
<value name="resized" get-method="isResized" set-
method="setResized"/>
</mapping>
<!-- Categories -->
<mapping class="org.prx.piece.category.PieceCategoryImpl"
abstract="true">
<value name="id" get-method="getId" set-method="setId"/>
<value name="name" get-method="getName" set-method="setName"/>
</mapping>
<mapping name="topic"
class="org.prx.piece.category.TopicCategory"
extends="org.prx.piece.category.PieceCategoryImpl">
<structure map-as="org.prx.piece.category.PieceCategoryImpl"/>
</mapping>
<mapping name="type" class="org.prx.piece.category.TypeCategory"
extends="org.prx.piece.category.PieceCategoryImpl">
<structure map-as="org.prx.piece.category.PieceCategoryImpl"/>
</mapping>
<!-- End Categories -->
<!-- Adjectives -->
<mapping name="adjective" class="org.prx.adjective.AdjectiveImpl">
<value name="id" get-method="getId" set-method="setId"/>
<value name="value" get-method="getAdjective" set-
method="setAdjective"/>
</mapping>
<!-- End Adjectives -->
<!-- Language -->
<mapping name="language" class="org.prx.util.Language">
<value name="id" get-method="getId" set-method="setId"/>
<value name="name" get-method="getName" set-method="setName"/>
</mapping>
<!-- End Language -->
</binding>
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users