插入成功了,但还是报错!用hibernate插入数据
用hibernate插入数据,明明插入成功了,但还是报错!!为啥啊???
package hibernates;import org.hibernate.Session;public class UserDao { Session session=null; public String saveMovie(Movie movie){ try{ session=CreateSession.getSession(); session.beginTransaction(); session.save(movie); session.beginTransaction().commit(); return "true"; }catch(Exception e){ session.getTransaction().rollback(); return "false"+e.getLocalizedMessage(); }finally{ CreateSession.closeSession(); } }}
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!-- Mapping file autogenerated by MyEclipse Persistence Tools--><hibernate-mapping> <class name="hibernates.Movie" table="movie" catalog="myweb"> <id name="id" type="java.lang.String"> <column name="id" length="45" /> </id> <property name="name" type="java.lang.String"> <column name="name" length="45" /> </property> </class></hibernate-mapping>
<?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="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="connection.url">jdbc:mysql://localhost:3306/myweb</property> <property name="connection.username">root</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.password"></property> <property name="hbm2ddl.auto">true</property> <mapping resource="hibernates/Movie.hbm.xml" /></session-factory></hibernate-configuration>