i am new to iberate, i just make an simple test program, and compile is good, but when execute, the error is at following, the project tree is also include please help, thanks in advance
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF/classes # java Test
Dec 14, 2012 2:56:28 PM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: HHH000040: Configuration resource: /hibernate.cfg.xml Exception in thread "main" org.hibernate.MappingException: invalid configuration at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2018) at org.hibernate.cfg.Configuration.configure(Configuration.java:1935) at org.hibernate.cfg.Configuration.configure(Configuration.java:1914) at Test.main(Test.java:12) Caused by: org.xml.sax.SAXParseException: Document is invalid: no grammar found. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF # ls -R .: classes compile.sh lib src web.xml
./classes: Student.hbm.xml Test.class example hibernate.cfg.xml struts.xml
./classes/example: Student.class
./lib: commons-fileupload-1.2.2.jar freemarker-2.3.19.jar ognl-3.0.5.jar commons-io-2.0.1.jar hibernate-commons-annotations-4.0.1.Final.jar spring-test-3.0.5.RELEASE.jar commons-lang-2.4.jar hibernate-core-4.1.8.Final.jar struts2-core-2.3.7.jar commons-lang3-3.1.jar javassist-3.11.0.GA.jar xwork-core-2.3.7.jar commons-logging-1.1.1.jar jboss-logging-3.1.0.GA.jar dom4j-1.6.1.jar jboss-transaction-api_1.1_spec-1.0.0.Final.jar
./src: example
./src/example: Student.java Test.java
********************************************* alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF/classes # cat Student.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">
<hibernate-mapping> <class name="example.Student" table="student"> <id name="studentId" column="student_id"> <generator class="increment" /> </id> <property name="firstName" type="string" column="first_name" /> <property name="lastName" type="string" column="last_name" /> <property name="address" type="string" column="address" /> </class> </hibernate-mapping>
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF/classes # cat hibernate.cfg.xml <hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://10.1.1.37/mytest</property> <property name="connection.username">test</property> <property name="connection.password">password</property>
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="show_sql">true</property>
<mapping resource="Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF/src/example # cat Test.java
import org.hibernate.Session; import example.Student; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration;
public class Test { public static void main(String[] args) { //Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Configuration conf=new Configuration().configure(); SessionFactory sf=conf.buildSessionFactory(); Session session=sf.openSession(); session.beginTransaction(); Student s = new Student("firstname", "lastname", "address"); session.save(s); session.getTransaction().commit(); } }
mysql> desc student; +------------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------------+------+-----+---------+----------------+ | student_id | bigint(10) unsigned | NO | PRI | NULL | auto_increment | | first_name | varchar(50) | YES | | NULL | | | last_name | varchar(50) | YES | | NULL | | | address | varchar(50) | YES | | NULL | | +------------+---------------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)
|