Hello again - now that I finally have get/set XML functions working I have run into more problems!!
I don't believe the <any> or org.hibernate.type.AnyType can be set to XML!! I get -
java.lang.UnsupportedOperationException: any types cannot be stringified
which is a pain but I could live with that!!
BUT WHEN I TRY TO REMOVE THE <ANY> node mapping from my hbm files - nothing changes!
If I don't add the node tag to the mapping it should be ignored - I still get this error. I have tried removing the node tag from the set ie in Arrest mapping as well as remove the node tag from the any side ie Attachment. I have even removed all the node tags from the whole Attachment.hbm.xml file!!
Any help about how to either 'stingify' this type or get hibernate to ignore the association would be great.
Shane
ebersoless@yahoo.com
Hibernate version:
3.0.5
Mapping documents:
<class name="mil.ditv.model.Arrest"
table="ditv_arrest"
node="Arrest"
>
...
<!-- NO node tags -->
<set name="attachments"
cascade="all-delete-orphan">
<key column="parent_id"/>
<one-to-many
class="mil.ditv.model.Attachment"
node="attachment"
/>
</set>
</class>
<class name="mil.ditv.model.Attachment" table="ditv_attachment">
...
<any name="parent"
meta-type="java.lang.String"
id-type="java.lang.String" >
<meta-value value="ditv_arrest" class="mil.ditv.model.Arrest"/>
<column name="parent_type"/>
<column name="parent_id"/>
</any>
</class>
Code between sessionFactory.openSession() and session.close():
// test attachment
Attachment attachment = new Attachment();
attachment.setName("test");
arrest.addAttachment(attachment);
dao.save(packet);
dump(dao.getXML(id),"packet4.xml");
// getXML method
public Document getXML(final ID id) throws ObjectRetrievalFailureException
{
return (Document) getHibernateTemplate().execute(new HibernateCallback()
{
public Object doInHibernate(Session session)
{
session.flush();
session.clear();
Session dom4jSession = session.getSession(EntityMode.DOM4J);
Document document = DocumentFactory.getInstance().createDocument();
Element element = (Element)dom4jSession.get(modelClass, id);
document.add(element);
return document;
}
});
}
Full stack trace of any exception that occurs:
[junit] ------------- ---------------- ---------------
[junit] Testcase: testCRUD(mil.ditv.dao.PacketDAOTest): Caused an ERROR
[junit] any types cannot be stringified
[junit] java.lang.UnsupportedOperationException: any types cannot be stringi
fied
[junit] at org.hibernate.type.AnyType.setToXMLNode(AnyType.java:160) [junit] at org.hibernate.property.Dom4jAccessor$ElementSetter.set(Dom4jA
ccessor.java:310)
[junit] at org.hibernate.tuple.AbstractEntityTuplizer.setPropertyValues(
AbstractEntityTuplizer.java:330)
[junit] at org.hibernate.persister.entity.AbstractEntityPersister.setPro
pertyValues(AbstractEntityPersister.java:3231)
[junit] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLo
ad.java:126)
[junit] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(
Loader.java:842)
[junit] at org.hibernate.loader.Loader.doQuery(Loader.java:717)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollec
tions(Loader.java:223)
[junit] at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
[junit] at org.hibernate.loader.collection.CollectionLoader.initialize(C
ollectionLoader.java:71)
[junit] at org.hibernate.persister.collection.AbstractCollectionPersiste
r.initialize(AbstractCollectionPersister.java:520)
[junit] at org.hibernate.event.def.DefaultInitializeCollectionEventListe
ner.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[junit] at org.hibernate.impl.SessionImpl.initializeCollection(SessionIm
pl.java:1593)
[junit] at org.hibernate.type.CollectionType.getCollection(CollectionTyp
e.java:501)
[junit] at org.hibernate.type.CollectionType.resolveKey(CollectionType.j
ava:335)
[junit] at org.hibernate.type.CollectionType.resolve(CollectionType.java
:329)
[junit] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLo
ad.java:113)
[junit] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(
Loader.java:842)
[junit] at org.hibernate.loader.Loader.doQuery(Loader.java:717)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollec
tions(Loader.java:223)
[junit] at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
[junit] at org.hibernate.loader.collection.CollectionLoader.initialize(C
ollectionLoader.java:71)
[junit] at org.hibernate.persister.collection.AbstractCollectionPersiste
r.initialize(AbstractCollectionPersister.java:520)
[junit] at org.hibernate.event.def.DefaultInitializeCollectionEventListe
ner.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[junit] at org.hibernate.impl.SessionImpl.initializeCollection(SessionIm
pl.java:1593)
[junit] at org.hibernate.type.CollectionType.getCollection(CollectionTyp
e.java:501)
[junit] at org.hibernate.type.CollectionType.resolveKey(CollectionType.j
ava:335)
[junit] at org.hibernate.type.CollectionType.resolve(CollectionType.java
:329)
[junit] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLo
ad.java:113)
[junit] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(
Loader.java:842)
[junit] at org.hibernate.loader.Loader.doQuery(Loader.java:717)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollec
tions(Loader.java:223)
[junit] at org.hibernate.loader.Loader.loadEntity(Loader.java:1782)
[junit] at org.hibernate.loader.entity.AbstractEntityLoader.load(Abstrac
tEntityLoader.java:93)
[junit] at org.hibernate.loader.entity.AbstractEntityLoader.load(Abstrac
tEntityLoader.java:81)
[junit] at org.hibernate.persister.entity.AbstractEntityPersister.load(A
bstractEntityPersister.java:2729)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.loadFromData
source(DefaultLoadEventListener.java:365)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(Defau
ltLoadEventListener.java:346)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.load(Default
LoadEventListener.java:123)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(
DefaultLoadEventListener.java:177)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(Defau
ltLoadEventListener.java:87)
[junit] at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:809)
[junit] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:749)
[junit] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:742)
[junit] at mil.ditv.dao.hibernate.BaseDAOHibernate$1.doInHibernate(BaseD
AOHibernate.java:139)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.execute(
HibernateTemplate.java:312)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.execute(
HibernateTemplate.java:288)
[junit] at mil.ditv.dao.hibernate.BaseDAOHibernate.getXML(BaseDAOHiberna
te.java:129)
[junit] at mil.ditv.dao.PacketDAOTest.testCRUD(PacketDAOTest.java:116)
[junit] Test mil.ditv.dao.PacketDAOTest FAILED
BUILD FAILED
Name and version of the database you are using:
MSSQL