Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error reading resource Hibernate

 
Grady Jamyson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Hibernate....
my xml file

===== MaterialDTO.hbm.xml =======
<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-mapping>
<class name="factory.material.MaterialDTO" table="material" >
<id name="matid" column="MATID" type="java.lang.Long" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="matname" column="MATNUM" type="java.lang.String" />
<property name="mattype" column="MATTYPE" type="java.lang.String" />
<property name="matname" column="MATNAME" type="java.lang.String" />
<property name="matprovider" column="MATPROVIDER" type="java.lang.String" />
<property name="matunit" column="MATUNIT" type="java.lang.String" />
<property name="matcost" column="MATCOST" type="java.lang.String" />
<property name="isdelete" column="ISDELETE" type="java.lang.String" />
</class>
</hibernate-mapping>


====== hibernate.cfg.xml =====
<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory>

<property name="connection.datasource">java:comp/env/jdbc/DBConn</property>

<property name="show_sql">true</property>

<property name="use_outer_join">true</property>

<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->
<mapping resource="factory/material/MaterialDTO.hbm.xml"/>

</session-factory>

</hibernate-configuration>




but when i want to add an object into database...
i saw the exception

javax.servlet.ServletException: net.sf.hibernate.MappingException: Error reading resource: factory/material/MaterialDTO.hbm.xml

any ideas?
thanks...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its probably a classpath issue with MaterialDTO.hbm.xml. Make sure its where it is supposed to be in you app's directory structure (check the Hibernate docs if you are not sure). Your mapping file look fine - its valid xml and superficially anyway looks plausible. You probably want to check your column names and data types though.
 
Grady Jamyson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think my classpath is OK.
Maybe the problem is from data type.
I would check it if it's correct.
Thanks.
 
Grady Jamyson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found the error.
The declaration of MaterialDTO.hbm.xml is WRONG.
Because I pasted it from hibernate.cfg.xml.

Anyway, thanks a lot.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This config may wrong ...

<mapping resource="factory/material/MaterialDTO.hbm.xml"/>

.....

I have some question to tell you ...

Which the server type for use in your project/work ?
 
Grady Jamyson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use Tomcat 5.0.24.
 
burt will
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, i am having the same problem and would like to know how you fixed it. i do not understand what you mean when you say

"...The declaration of MaterialDTO.hbm.xml is WRONG.
Because I pasted it from hibernate.cfg.xml.
...."


can you please elaborate...thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic