Hello
I am french (so i dont speak english very well) and i'm starting with hibernate.
I have a probleme using it. I want to generate tables of database from mapping file.
Hibernate version: 3.0
Mapping documents:
this is the tree of my project
Code:
src
+money.config
++TestClass.hbm.xml
+money.javabeans
++TestClass.java
+hibernate.cfg.xml
webroot
+WEb-INF
++test.jsp
this is my hibernate.cfg.xml
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.username">sylvain</property>
<property name="connection.url">jdbc:mysql://localhost:3306/money</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="myeclipse.connection.profile">mysql money</property>
<property name="connection.password">6LMmar1e</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<mapping resource="money/config/TestClass.hbm.xml" />
</session-factory>
</hibernate-configuration>
this is money/config/TestClass.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="money.javabeans">
<class name="TestClass" table="TESTCLASSE" lazy="false">
<id name="i" column="i" type="java.lang.Integer">
<generator class="native" />
</id>
<property name="a" column="a" type="java.lang.Integer" not-null="true" length="10" />
</class>
</hibernate-mapping>
I try to generate database with code in a JSP using Schema Export
Code:
...
<title>Insert title here</title>
</head>
<body>
<%
Configuration cfg = new Configuration()
.addResource("money/config/TestClass.hbm.xml");
cfg.configure(new File("C:/Documents and Settings/sly33/workspace/Money/src/hibernate.cfg.xml"));
SchemaExport sce = new SchemaExport(cfg);
sce.setOutputFile("c:/test.sql");
sce.create(true,true);
%>
</body>
</html>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
I have an error on the first line of code, when i add a ressource to the configuration.
Somebody can help ME ?
Code:
exception
org.apache.jasper.JasperException: Could not read mappings from resource: money/config/TestClass.hbm.xml
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
cause mère
org.hibernate.MappingException: Could not read mappings from resource: money/config/TestClass.hbm.xml
org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
org.hibernate.cfg.Configuration.configure(Configuration.java:1344)
org.apache.jsp.test_jsp._jspService(test_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Name and version of the database you are using:mYSQL 5
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: