chun888 发表于 2018-1-14 23:51:21

Myeclipse下建立Hibernate框架不能在mysql建立表

测试类
package club.mochunrong.hibernate.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

import club.mochunrong.hibernate.bean.User;

public class HibernateTest {

        public static void main(String[] args)
          {
          try
          {
              Configuration configuration = new Configuration().configure();
             
              System.out.println(configuration);
              ServiceRegistry serviceRegistry =
                new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
                .build();
              System.out.println(serviceRegistry);
              SessionFactory sf = configuration.buildSessionFactory(serviceRegistry);   
              System.out.println(sf);
             

          
          }
          catch (Exception e)
          {
                 e.printStackTrace();
          }
          }

}




配置文件
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
        <session-factory>
                <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
                <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
                <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/haha</property>
                <property name="hibernate.connection.username">root</property>
                <property name="hibernate.connection.password">chunrong</property>
                <property name="hibernate.c3p0.max_size">10</property>
                <property name="hibernate.c3p0.min_size">2</property>
                <property name="hibernate.c3p0.timeout">5000</property>
                <property name="hibernate.show_sql">true</property>
                <property name="hibernate.format_sql">true</property>
                <property name="hibernate.hbm2ddl.auto">update</property>
                <mapping class="club.mochunrong.hibernate.bean.User" />


        </session-factory>
</hibernate-configuration>


持久化类

package club.mochunrong.hibernate.bean;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity(name="tb_user")
public class User implements Serializable
{
@Id
@Column(name="TB_ID")
private int id;
@Column(name="TB_NAME")
private String name;
private int age;

public int getId()
{
    return this.id;
}

public void setId(int id)
{
    this.id = id;
}

public String getName()
{
    return this.name;
}

public void setName(String name)
{
    this.name = name;
}

public int getAge()
{
    return this.age;
}

public void setAge(int age)
{
    this.age = age;
}

public String toString()
{
    return "User ";
}
}


===========================================================================
                                                console的打印日志
===========================================================================
一月 14, 2018 11:37:00 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.12.Final}
一月 14, 2018 11:37:00 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.max_fetch_depth=5, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.connection.pool_size=5}
org.hibernate.cfg.Configuration@1d422d
一月 14, 2018 11:37:00 下午 org.hibernate.spatial.integration.SpatialService <init>
INFO: HHH80000001: hibernate-spatial integration enabled : true
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl@1d4520b
一月 14, 2018 11:37:00 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
一月 14, 2018 11:37:00 下午 org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://127.0.0.1:3306/haha
一月 14, 2018 11:37:00 下午 org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH10001001: Connection properties: {user=root, password=****}
一月 14, 2018 11:37:00 下午 org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH10001003: Autocommit mode: false
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
MLog initialization issue: slf4j found no binding or threatened to use its (dangerously silent) NOPLogger. We consider the slf4j library not found.
一月 14, 2018 11:37:00 下午 com.mchange.v2.log.MLog
信息: MLog clients using java 1.4+ standard logging.
一月 14, 2018 11:37:01 下午 com.mchange.v2.c3p0.C3P0Registry
信息: Initializing c3p0-0.9.5.2
一月 14, 2018 11:37:01 下午 org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH10001007: JDBC isolation level: <unknown>
一月 14, 2018 11:37:01 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@eb25adb5 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@32f3b794 [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, identityToken -> 1hgery99s1w2efcj18ld78h|1835c46, idleConnectionTestPeriod -> 0, initialPoolSize -> 2, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 5000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 2, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@edb4e294 [ description -> null, driverClass -> null, factoryClassLocation -> null, forceUseNamedDriverClass -> false, identityToken -> 1hgery99s1w2efcj18ld78h|386f16, jdbcUrl -> jdbc:mysql://127.0.0.1:3306/haha, properties -> {user=******, password=******} ], preferredTestQuery -> null, privilegeSpawnedThreads -> false, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, extensions -> {}, factoryClassLocation -> null, identityToken -> 1hgery99s1w2efcj18ld78h|3ef382, numHelperThreads -> 3 ]
一月 14, 2018 11:37:01 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
一月 14, 2018 11:37:01 下午 org.hibernate.envers.boot.internal.EnversServiceImpl configure
INFO: Envers integration enabled? : true
一月 14, 2018 11:37:01 下午 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
org.hibernate.internal.SessionFactoryImpl@16c53fc



===========================================================================


导包问题,我把hibernate的所有包都导进去了,mysql驱动包也导了,


数据库能正常运行使用。







请问各位有经验的大佬是否遇到这样的事情,或者知道怎么解决的告诉我一声谢谢。


                                                        我设置了回答有奖励

夜色下的俯瞰 发表于 2018-1-16 09:54:40

配置文件里没有引入映射文件
<mapping class="club.mochunrong.hibernate.bean.User" />   

chun888 发表于 2018-1-16 15:56:39

夜色下的俯瞰 发表于 2018-1-16 09:54
配置文件里没有引入映射文件

我用注解的,不是属性文件

@Entity(name="tb_user")

持久化类里面上有的

夜色下的俯瞰 发表于 2018-1-17 09:05:47

chun888 发表于 2018-1-16 15:56
我用注解的,不是属性文件

@Entity(name="tb_user")


用注解也要配置啊,我之前说的不清楚,你要在配置文件中注册的注解了的实体类
<mapping class="club.mochunrong.hibernate.bean.User" />   

及格再改名 发表于 2018-1-17 09:37:17

{:10_254:}

段坤11 发表于 2018-3-12 16:28:32

我也碰到差不多的问题

chun888 发表于 2018-4-26 11:11:45

段坤11 发表于 2018-3-12 16:28
我也碰到差不多的问题

其实问题早已自己解决了,想知道该论坛能否有人给出我满意答案

multitate 发表于 2018-7-12 14:33:19

{:5_106:}{:5_106:}

独吟月上 发表于 2018-7-22 20:40:09

{:10_277:}

CCCFC 发表于 2018-8-8 21:24:54

路过学习哈

ck567 发表于 2018-8-15 12:17:41

{:5_90:}

whdd 发表于 2018-9-7 21:42:33

加油

whdd 发表于 2018-9-16 11:56:26

宝宝

whdd 发表于 2018-9-16 11:57:00

&#128552;

钱闻韬 发表于 2018-9-16 17:24:47

...
页: [1]
查看完整版本: Myeclipse下建立Hibernate框架不能在mysql建立表