-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: a problem about exporting and importing data with xml
PostPosted: Tue May 24, 2005 8:52 am 
Newbie

Joined: Tue May 24, 2005 7:54 am
Posts: 4
Location: Beijing in China
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: hibernate 3.0.4

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping
auto-import="true"
default-access="property"
default-cascade="none"
default-lazy="true"
package="cn.ac.iscas.itechs.qms.projectie.hibernate"
>
<class
abstract="false"
dynamic-insert="false"
dynamic-update="false"
mutable="true"
name="ReviewReport"
node="ReviewReport"
optimistic-lock="version"
polymorphism="implicit"
select-before-update="false"
table="review_report"
>
<id
column="REVIEW_REPORT_ID"
name="Id"
node="@Id"
type="integer"
>
<generator class="identity" />
</id>
<property
column="REVIEW_DATE"
insert="true"
lazy="false"
length="10"
name="ReviewDate"
node="ReviewDate"
not-null="false"
optimistic-lock="true"
type="date"
unique="false"
update="true"
/>
<property
column="REPORT_NAME"
insert="true"
lazy="false"
length="60"
name="ReportName"
node="ReportName"
not-null="false"
optimistic-lock="true"
type="string"
unique="false"
update="true"
/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
private ProjectInfoDAO projectInfoDAO;
private ProjectInfo projectInfo;
private Session session;
private Transaction transaction;
private Session dom4jSession;
private List result;
private Document document;
private File file;

protected void setUp(){
_RootDAO.initialize();
projectInfoDAO=new ProjectInfoDAO();
projectInfo=new ProjectInfo();
session=projectInfoDAO.createNewSession();
dom4jSession = session.getSession(EntityMode.DOM4J);
transaction=session.beginTransaction();
document=DocumentHelper.createDocument();
file=new File("D:/test.xml");
}

/**
* export data to xml files with dom4j
* @throws IOException
*
*/
public void testRetrieveProject() throws IOException{
result=dom4jSession.createQuery("from ReviewReport as r where r.Id=2").list();
for(int i=0;i<result.size();i++){
Element element=(Element)result.get(i);
document.add(element);
}
XMLWriter output;
output = new XMLWriter(
new FileOutputStream(file));
output.write(document);
output.close();
}
/**
* import data from xml to finishing overwrite
* @throws DocumentException
* @throws FileNotFoundException
*
*/
public void testReadXml() throws FileNotFoundException, DocumentException{
SAXReader saxReader = new SAXReader();
document = saxReader.read(new FileInputStream(file));
result=document.selectNodes("//ReviewReport");
Iterator repIterator=result.iterator();
while (repIterator.hasNext()) {
Object report = repIterator.next(); dom4jSession.saveOrUpdate("cn.ac.iscas.itechs.qms.projectie.hibernate.ReviewReport"
,report);

}
}


Full stack trace of any exception that occurs:
org.hibernate.HibernateException: could not parse XML
at org.hibernate.type.DateType.fromStringValue(DateType.java:95)
at org.hibernate.type.NullableType.fromXMLString(NullableType.java:102)
at org.hibernate.type.NullableType.fromXMLNode(NullableType.java:126)
at org.hibernate.property.Dom4jAccessor$ElementGetter.get(Dom4jAccessor.java:192)
at org.hibernate.tuple.AbstractTuplizer.getPropertyValues(AbstractTuplizer.java:174)
at org.hibernate.persister.entity.BasicEntityPersister.getPropertyValues(BasicEntityPersister.java:2929)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:84)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:329)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at cn.ac.iscas.itechs.qms.projectie.test.TestRelationTest.tearDown(TestRelationTest.java:64)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: java.text.ParseException: Unparseable date: "22 9 2004"
at java.text.DateFormat.parse(Unknown Source)
at org.hibernate.type.DateType.fromStringValue(DateType.java:92)
... 23 more


Name and version of the database you are using:
mysql 4.0


The generated SQL (show_sql=true):
I tested the exporting and importing process with junit,but I found that exception happened as long as the field had a type of date. The actual data has a format such as "2004-09-22" in the database,but when it's exported to the xml, it's converted to the format "22 9 2004" and the exception happens. When the file is import after it's modified,it cann't update the field yet, for the same exception happened.


Debug level Hibernate log excerpt:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.