控制台:14-07-17 13:45:32 INFO Environment:509 - Hibernate 3.2.2
14-07-17 13:45:32 INFO Environment:542 - hibernate.properties not found
14-07-17 13:45:32 INFO Environment:676 - Bytecode provider name : cglib
14-07-17 13:45:32 INFO Environment:593 - using JDK 1.4 java.sql.Timestamp handling
14-07-17 13:45:32 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
14-07-17 13:45:32 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
14-07-17 13:45:32 INFO Configuration:553 - Reading mappings from resource : com/exe/hib/bean/Student.hbm.xml
14-07-17 13:45:32 INFO HbmBinder:300 - Mapping class: com.exe.hib.bean.Student -> stu
14-07-17 13:45:32 INFO Configuration:1541 - Configured SessionFactory: null
14-07-17 13:45:33 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
14-07-17 13:45:33 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
14-07-17 13:45:33 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
14-07-17 13:45:33 INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/test
14-07-17 13:45:33 INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****}
14-07-17 13:45:34 INFO SettingsFactory:89 - RDBMS: MySQL, version: 5.0.27-community-nt
14-07-17 13:45:34 INFO SettingsFactory:90 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.11 ( $Date: 2005-09-21 18:20:03 +0000 (Wed, 21 Sep 2005) $, $Revision: 4287 $ )
14-07-17 13:45:34 INFO Dialect:152 - Using dialect: org.hibernate.dialect.MySQLDialect
14-07-17 13:45:34 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
14-07-17 13:45:34 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
14-07-17 13:45:34 INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
14-07-17 13:45:34 INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
14-07-17 13:45:34 INFO SettingsFactory:154 - JDBC batch size: 15
14-07-17 13:45:34 INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled
14-07-17 13:45:34 INFO SettingsFactory:162 - Scrollable result sets: enabled
14-07-17 13:45:34 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): enabled
14-07-17 13:45:34 INFO SettingsFactory:178 - Connection release mode: auto
14-07-17 13:45:34 INFO SettingsFactory:202 - Maximum outer join fetch depth: 2
14-07-17 13:45:34 INFO SettingsFactory:205 - Default batch fetch size: 1
14-07-17 13:45:34 INFO SettingsFactory:209 - Generate SQL with comments: disabled
14-07-17 13:45:34 INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
14-07-17 13:45:34 INFO SettingsFactory:382 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
14-07-17 13:45:34 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
14-07-17 13:45:34 INFO SettingsFactory:221 - Query language substitutions: {}
14-07-17 13:45:34 INFO SettingsFactory:226 - JPA-QL strict compliance: disabled
14-07-17 13:45:34 INFO SettingsFactory:231 - Second-level cache: enabled
14-07-17 13:45:34 INFO SettingsFactory:235 - Query cache: disabled
14-07-17 13:45:34 INFO SettingsFactory:369 - Cache provider: org.hibernate.cache.NoCacheProvider
14-07-17 13:45:34 INFO SettingsFactory:250 - Optimize cache for minimal puts: disabled
14-07-17 13:45:34 INFO SettingsFactory:259 - Structured second-level cache entries: disabled
14-07-17 13:45:34 INFO SettingsFactory:286 - Statistics: disabled
14-07-17 13:45:34 INFO SettingsFactory:290 - Deleted entity synthetic identifier rollback: disabled
14-07-17 13:45:34 INFO SettingsFactory:305 - Default entity-mode: pojo
14-07-17 13:45:34 INFO SettingsFactory:309 - Named query checking : enabled
14-07-17 13:45:34 INFO SessionFactoryImpl:161 - building session factory
14-07-17 13:45:34 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
ccccccccc
14-07-17 13:45:34 WARN JDBCExceptionReporter:77 - SQL Error: 1064, SQLState: 42000
14-07-17 13:45:34 ERROR JDBCExceptionReporter:78 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.stu (stu_name, stu_sex, stu_age, stu_address, stu_description) values ('a', '?'' at line 1
org.hibernate.exception.SQLGrammarException: could not insert: [com.exe.hib.bean.Student]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2154)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2634)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at com.exe.hib.daoImpl.StudentDaoImpl.createStu(StudentDaoImpl.java:30)
at com.exe.hib.bussinessManage.BM.main(BM.java:22)
Caused by: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.stu (stu_name, stu_sex, stu_age, stu_address, stu_description) values ('a', '?'' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:933)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1162)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1079)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1064)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
... 17 more
BM:
public class BM {
public static void main(String[] args) {
Student stu=new Student();
stu.setStuName("dddddd");
// System.out.println("execute to here now!");
stu.setStuSex("女");
stu.setStuName("a");
stu.setStuAddress("aa");
stu.setStuAge(12);
stu.setStuDescription("嗷嗷嗷");
new StudentDaoImpl().createStu(stu);
}
daoImpl:
package com.exe.hib.daoImpl;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.exe.hib.bean.Student;
import com.exe.hib.dao.StudentDao;
import com.exe.hib.util.HibernateUtil;
/**
*@author:
*@version:
*@date:
*@description:
*/
public class StudentDaoImpl implements StudentDao {
static Session session = null;
public void createStu(Student stu) {
// TODO Auto-generated method stub
try{
//System.out.println("ccccccccc");
session=HibernateUtil.currentSession();
//
Transaction tx=session.beginTransaction();
session.save(stu);
tx.commit();
}catch(HibernateException he){
he.printStackTrace();
}finally{
HibernateUtil.closeSession(session);
}
}
public void deleteStu(int id) {
// TODO Auto-generated method stub
}
public List queryStu(int id) {
// TODO Auto-generated method stub
return null;
}
public void updateStu(Student stu) {
// TODO Auto-generated method stub
}
}
}
bean:package com.exe.hib.bean;
/**
* Student entity. @author MyEclipse Persistence Tools
*/
public class Student implements java.io.Serializable {
// Fields
private Integer stuId;
private String stuName;
private String stuSex;
private Integer stuAge;
private String stuAddress;
private String stuDescription;
// Constructors
/** default constructor */
public Student() {
}
/** minimal constructor */
public Student(Integer stuId) {
this.stuId = stuId;
}
/** full constructor */
public Student(Integer stuId, String stuName, String stuSex, Integer stuAge,
String stuAddress, String stuDescription) {
this.stuId = stuId;
this.stuName = stuName;
this.stuSex = stuSex;
this.stuAge = stuAge;
this.stuAddress = stuAddress;
this.stuDescription = stuDescription;
}
// Property accessors
public Integer getStuId() {
return this.stuId;
}
public void setStuId(Integer stuId) {
this.stuId = stuId;
}
public String getStuName() {
return this.stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public String getStuSex() {
return this.stuSex;
}
public void setStuSex(String stuSex) {
this.stuSex = stuSex;
}
public Integer getStuAge() {
return this.stuAge;
}
public void setStuAge(Integer stuAge) {
this.stuAge = stuAge;
}
public String getStuAddress() {
return this.stuAddress;
}
public void setStuAddress(String stuAddress) {
this.stuAddress = stuAddress;
}
public String getStuDescription() {
return this.stuDescription;
}
public void setStuDescription(String stuDescription) {
this.stuDescription = stuDescription;
}
}
映射文件:
<?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="com.exe.hib.bean.Student" table="stu" schema="dbo" catalog="test">
<id name="stuId" type="java.lang.Integer">
<column name="stu_Id" />
<generator class="identity"></generator>
</id>
<property name="stuName" type="java.lang.String">
<column name="stu_name" length="10" />
</property>
<property name="stuSex" type="java.lang.String">
<column name="stu_sex" length="10" />
</property>
<property name="stuAge" type="java.lang.Integer">
<column name="stu_age" length="20" />
</property>
<property name="stuAddress" type="java.lang.String">
<column name="stu_address" length="20" />
</property>
<property name="stuDescription" type="java.lang.String">
<column name="stu_description" length="50" />
</property>
</class>
</hibernate-mapping>
cfg:
<?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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="show_sql">ture</property>
<property name="format_sql">false</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="connection.username">root</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<mapping resource="com/exe/hib/bean/Student.hbm.xml" />
</session-factory>
</hibernate-configuration>
谢谢!!
相关推荐
- `show_sql`:如果设为true,Hibernate会在控制台打印执行的SQL语句,便于调试,这里的值为true。 4. **Session策略**: - `hibernate.current_session_context_class`:设置当前Session的上下文类,这里是`...
当设置为 true 时,Hibernate 将输出所有 SQL 语句到控制台,方便开发者调试和优化数据库操作。 3. hibernate.format_sql hibernate.format_sql 参数用于在 log 和 console 中打印出更漂亮的 SQL。其取值为 true ...
在Java开发中,Hibernate是一个非常流行的ORM(对象关系映射)框架,它允许开发者通过面向对象的方式来操作数据库,而无需直接编写SQL语句。在这个场景中,我们将探讨如何使用Hibernate与SQL Server 2005数据库进行...
【标题】"Hibernate 显示数据库数据" 在Java开发中,Hibernate是一个非常流行的对象关系映射(ORM)框架,它简化了数据库操作,使得开发者可以用Java对象来操作数据库记录。本教程针对初学者,将介绍如何使用...
**Hibernate的Java控制台程序Demo**是用于演示如何在Java应用程序中使用Hibernate框架进行对象关系映射(ORM)操作的实例。在这个项目中,我们将会深入理解Hibernate的核心概念,包括配置、实体类、持久化、会话管理...
**Hibernate的Java控制台应用Demo**是用于演示如何在Java应用程序中使用Hibernate框架进行对象关系映射(ORM)操作的实例。在这个项目中,我们将会深入理解Hibernate的核心概念,包括配置、实体类定义、持久化操作...
2. **`hibernate.show_sql`**:控制是否在控制台上显示生成的SQL语句。这对于调试非常有用。 - 示例: ```properties hibernate.show_sql=true ``` 3. **`hibernate.format_sql`**:控制输出到日志或控制台的...
4. **显示SQL语句**:设置为`true`表示在控制台输出SQL语句。 5. **SQL格式化**:设置为`true`表示格式化输出SQL语句,便于阅读。 6. **映射文件路径**:指定实体类与数据库表之间的映射文件路径。 #### 实体类与...
此外,根据实际数据库环境选择合适的 SQL 方言也是十分重要的一步,它能够确保 Hibernate 生成的 SQL 语句与数据库完美匹配。希望本文能够帮助您更好地理解和应用 Hibernate 配置,为您的项目带来更大的价值。
Hibernate 框架是Java开发中的一个流行持久化框架,用于简化数据库操作。在SSH(Spring、Struts、Hibernate)架构中,...同时,保持良好的日志记录和监控也有助于了解Hibernate的运行状况,并在必要时进行调整。
3. `lazy="false"` 表示实体加载策略,不启用延迟加载,意味着关联的对象在加载时会立即加载。 4. `<id>` 元素定义主键,`generator` 属性指定生成策略,`identity` 表示由数据库自动生成 ID。 5. `<property>` 元素...
2. **hibernate.show_sql**:当设置为`true`时,Hibernate会在控制台上打印出执行的所有SQL语句,这对于调试和理解查询行为非常有用。 3. **hibernate.format_sql**:如果设置为`true`,Hibernate会格式化输出的SQL...
如果不设置该属性,Hibernate 将不会输出 SQL 语句。 hibernate.format_sql Hibernate.format_sql 属性用于控制 Hibernate 是否在 log 和 console 中打印出更漂亮的 SQL 语句。该属性的值可以是 true 或 false,...
- `hibernate.show_sql`:如果设为`true`,Hibernate会在控制台输出所有执行的SQL语句。 - `hibernate.format_sql`:如果设为`true`,输出格式化的SQL,使日志和控制台的输出更易读。 - `hibernate.default_...
3. **hibernate.format_sql**: 当设置为`true`时,Hibernate会在控制台和日志中打印格式化的、更易读的SQL语句。 4. **hibernate.default_schema**和**hibernate.default_catalog**: 分别用于指定默认的数据库模式...
上述配置中的`spring.jpa.hibernate.ddl-auto`用于控制数据库表的自动创建、更新等操作,`spring.jpa.show-sql`则用于在控制台显示执行的SQL语句。 现在,我们创建实体类。假设我们有一个`User`实体,如下所示: `...
- `show_sql`:表示是否在控制台打印SQL语句,默认值为`false`。 - `format_sql`:表示是否格式化SQL语句,默认值为`false`。 - `hbm2ddl.auto`:设置Hibernate在启动时对数据库表的操作模式,常见的值有`create`...
这样,Hibernate执行的所有SQL语句都会在控制台上显示出来,便于调试和分析。但需要注意的是,这种做法会增加系统的运行负担,不利于性能优化,因此在生产环境中应谨慎使用。 ### Hibernate的缓存策略 Hibernate...
- `hibernate.show_sql`: 如果设置为`true`,Hibernate将在控制台打印出执行的SQL语句。 - `hibernate.format_sql`: 如果设置为`true`,将会格式化输出的SQL,便于阅读。 5. **其他重要配置** - `hibernate.hbm2...
2. **hibernate.show_sql**:如果设置为`true`,Hibernate将在控制台上打印出执行的所有SQL语句,这对于调试非常有用。 3. **hibernate.format_sql**:当设置为`true`时,Hibernate会格式化输出的SQL,使其更易读。...