I have created two java files - Team.java & Player.java with their respective tables - team , player .I have created the mapping files too and made the entry in configuration file too.The mapping files are: Team.hbm.xml:- <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
org.hibernate.MappingException: Could not read mappings from resource: abc/hiber/Team.hbm.xml at org.hibernate.cfg.Configuration.addClass(Configuration.java:506) at abc.hiber.teamexample.main(teamexample.java:31) Caused by: org.hibernate.MappingException: Could not parse mapping document in input stream at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:431) at org.hibernate.cfg.Configuration.addClass(Configuration.java:503) ... 1 more Caused by: org.dom4j.DocumentException: Error on line 2 of document : XML declaration may only begin entities. Nested exception: XML declaration may only begin entities. at org.dom4j.io.SAXReader.read(SAXReader.java:482) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:422) ... 2 more Exception in thread "main" Can u help me .Any help would be appreciated Thanks in Advance
thanks paul, but removing this line from .hbm.xml files did nt help .
well my package name is : abc.hiber , so i have used abc.hiber.Team.hbm.xml in the mapping document and in .cfg.xml file , is that correct or should i use Team.hbm.xml.
Also i have saved both .cfg.xml file &.hbm.xml in same folder , the error what came was Duplicate Mapping Exception , where should i place these files - in same folder that in hiber folder or one of these should be kept somewhere else.
Don't remove that line. You can only have one <?xml version="1.0"?> in a file, and you can't have anything in the file before <?xml version="1.0"?>. This is what your parsing exception is telling you. Your configuration must be OK, since Hibernate is finding Team.hbm.xml, but Team.hbm.xml is not valid xml.
Thanks Paul , my problem has been figured . The insert into Team is working , but entry in players table is not coming . when i run the hibernate code , the following thing comes on console :
Inserting Records Hibernate: insert into teams (team_name, city, team_id) values (?, ?, ?) Hibernate: update players set first_name=?, last_name=?, team_id=? where player_id=? org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1 at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:27) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2204) at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374) at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at abc.hiber.teamexample.main(teamexample.java:43)
insert into teams is fine , but why update in players and not insert , does it has to take something from - inverse="true" that i used in team.hbm.xml. Also , why this stale state exception is coming ?
madhur taneja wrote:Thanks Paul , my problem has been figured .
The insert into Team is working , but entry in players table is not coming .
when i run the hibernate code , the following thing comes on console :
Inserting Records
Hibernate:
insert
into
teams
(team_name, city, team_id)
values
(?, ?, ?)
Hibernate:
update
players
set
first_name=?,
last_name=?,
team_id=?
where
player_id=?
org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:27)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2204)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at abc.hiber.teamexample.main(teamexample.java:43)
insert into teams is fine , but why update in players and not insert , does it has to take something from - inverse="true" that i used in team.hbm.xml.
Also , why this stale state exception is coming ?
Thanks.
Hello Madhur,
I am facing a similar issue, how did you solve this ?
Post by:autobot
Hot dog! An advertiser loves us THIS much:
a bit of art, as a gift, the permaculture playing cards