hebinate配置好hibernate后,可以使用,如下:
2014-5-14 19:46:12 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
2014-5-14 19:46:12 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.5.Final}
2014-5-14 19:46:12 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
2014-5-14 19:46:12 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
2014-5-14 19:46:13 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
2014-5-14 19:46:13 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
2014-5-14 19:46:13 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2014-5-14 19:46:13 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
2014-5-14 19:46:13 org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator instantiateExplicitConnectionProvider
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.connection.C3P0ConnectionProvider
2014-5-14 19:46:13 org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/zhangmeng
2014-5-14 19:46:13 org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH000046: Connection properties: {user=zhangmeng, password=****}
2014-5-14 19:46:13 org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH000006: Autocommit mode: false
2014-5-14 19:46:13 org.hibernate.c3p0.internal.C3P0ConnectionProvider warnPropertyConflict
WARN: HHH010001: Both hibernate-style property 'hibernate.c3p0.timeout' and c3p0-style property 'c3p0.maxIdleTime' have been set in Hibernate properties. Hibernate-style property 'hibernate.c3p0.timeout' will be used and c3p0-style property 'c3p0.maxIdleTime' will be ignored!
2014-5-14 19:46:13 org.hibernate.c3p0.internal.C3P0ConnectionProvider warnPropertyConflict
WARN: HHH010001: Both hibernate-style property 'hibernate.c3p0.timeout' and c3p0-style property 'hibernate.c3p0.maxIdleTime' have been set in Hibernate properties. Hibernate-style property 'hibernate.c3p0.timeout' will be used and c3p0-style property 'hibernate.c3p0.maxIdleTime' will be ignored!
2014-5-14 19:46:13 org.hibernate.c3p0.internal.C3P0ConnectionProvider warnPropertyConflict
WARN: HHH010001: Both hibernate-style property 'hibernate.c3p0.idle_test_period' and c3p0-style property 'c3p0.idleConnectionTestPeriod' have been set in Hibernate properties. Hibernate-style property 'hibernate.c3p0.idle_test_period' will be used and c3p0-style property 'c3p0.idleConnectionTestPeriod' will be ignored!
2014-5-14 19:46:13 org.hibernate.c3p0.internal.C3P0ConnectionProvider warnPropertyConflict
WARN: HHH010001: Both hibernate-style property 'hibernate.c3p0.idle_test_period' and c3p0-style property 'hibernate.c3p0.idleConnectionTestPeriod' have been set in Hibernate properties. Hibernate-style property 'hibernate.c3p0.idle_test_period' will be used and c3p0-style property 'hibernate.c3p0.idleConnectionTestPeriod' will be ignored!
2014-5-14 19:46:13 com.mchange.v2.log.MLog <clinit>
信息: MLog clients using java 1.4+ standard logging.
2014-5-14 19:46:13 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
2014-5-14 19:46:14 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@bf8db7be [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@9398d83d [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> Test, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1b60sj3911xipsdmcc20yq|2e1551b0, idleConnectionTestPeriod -> 120, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 120, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@f539a77d [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1b60sj3911xipsdmcc20yq|7c0b6548, jdbcUrl -> jdbc:mysql://localhost:3306/zhangmeng, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1b60sj3911xipsdmcc20yq|1f57ea4a, numHelperThreads -> 3 ]
2014-5-14 19:46:14 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2014-5-14 19:46:14 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
2014-5-14 19:46:15 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
2014-5-14 19:46:15 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
2014-5-14 19:46:15 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
2014-5-14 19:46:15 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
2014-5-14 19:46:15 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
2014-5-14 19:46:15 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: zhangmeng.events
2014-5-14 19:46:15 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [title, age, event_date, event_id]
2014-5-14 19:46:15 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
2014-5-14 19:46:15 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
2014-5-14 19:46:15 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Hibernate: insert into events (age, EVENT_DATE, title) values (?, ?, ?)
数据库也有插入,测试程序如下:
public class EnentManger {
public static void main(String[] args) {
EnentManger mgr = new EnentManger();
mgr.createAndStoreEvent("Myqq",new Date(),25);
HibernateUtil.getSessionFactory().close();
}
private void createAndStoreEvent(String tit, Date theDate,int d) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event heEvent=new Event();
heEvent.setTitle(tit);
heEvent.setDate(theDate);
heEvent.setAge(d);
session.save(heEvent);
session.getTransaction().commit();
}
}
但是问题出现了,数据库的插入条目显示如下:
无论 mgr.createAndStoreEvent("Myqq",new Date(),25);这句怎么设置数据,title和age值都不变,但是date变了,说明还是执行的啊,event表的类文件如下:
package main.java.org.hibernate.tutorial.domain;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;
@Entity(name="events")//指定表名时必须在entity里设置,在@table里设置会产生异常
public class Event {
private Long id;
private String title;
private Date date;
private int age;
public Event() {}
@GenericGenerator(name = "generator", strategy = "native")
@Id
@GeneratedValue(generator = "generator")
@Column(name="EVENT_ID",unique = true, nullable = false)
public Long getId() {
return id;
}
private void setId(Long id) {
this.id = id;
}
@Column(name="EVENT_DATE")
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
@Column(name="title")
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Column(name="age")
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
希望有大神给出解释啊,是不是c3p0的原因啊