错误一
Hibernate(二):MySQL server version for the right syntax to use near 'type=InnoDB' at line x
参考:http://www.cnblogs.com/yy3b2007com/p/6714092.html
主要是将配置文件修改为:
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<session-factory>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql:///useroa?useUnicode=true&characterEncoding=UTF-8</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<mapping resource="com/winney/entity/Students.hbm.xml" />
<mapping resource="com/winney/entity/Users.hbm.xml" />
</session-factory>
错误二Hibernate出现“Error parsing JNDI name []”错误解决方法
参考:https://www.juwends.com/tech/java/java_study_20151025_error-parsing-jndi-name.html
主要是将<session-factory>里面有esclips添加的name属性删除。
hibernate5注册服务创表:
//创建配置对象
Configuration config = new Configuration().configure();
// 创建服务注册对象
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
//创建sessionfactory
SessionFactory sessionFactory = config.buildSessionFactory();
//创建session对象
Session session = sessionFactory.getCurrentSession();
//创建schemaEXport对象
Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
SchemaExport schemaExport = new SchemaExport();
schemaExport.create(EnumSet.of(TargetType.DATABASE), metadata);