-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problems with Schema Export
PostPosted: Sat Dec 01, 2007 5:36 pm 
Newbie

Joined: Wed Dec 13, 2006 9:34 am
Posts: 6
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:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 02, 2007 6:53 pm 
Newbie

Joined: Sat Jul 14, 2007 11:50 am
Posts: 12
Location: the Burgh
I've never used schema export within a page... clearly you're just using it to test, because it's not a good idea from a design perspective.

That said, it looks like you just need to import that resource into the JSP page. ie at the top of the page you need something like this:

<%@ page import="package.resource" %>

Hope that helps.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 02, 2007 11:58 pm 
Newbie

Joined: Fri Aug 31, 2007 11:58 am
Posts: 19
Just to highlight ,what you are doing i.e Calling Schema Export from JSP is really really wierd.

_________________
Note:Don't forget to rate,if useful.

Blog:http://elope.wordpress.com/


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

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.