【问题标题】:Troubles with Hibernate configuration with H2使用 H2 进行 Hibernate 配置的问题
【发布时间】:2012-05-01 14:19:09
【问题描述】:

我正在尝试将 Hibernate 配置为在 H2 上工作,但是当我打电话时:
Configuration cfg = new Configuration().configure();
new Configuration() 的调用会输出以下内容:
מאי 01, 2012 5:10:41 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
מאי 01, 2012 5:10:41 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.1}
מאי 01, 2012 5:10:41 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
מאי 01, 2012 5:10:41 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist

但这并不会停止执行...在此之后,对.configure() 的调用输出:
מאי 01, 2012 5:14:39 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
מאי 01, 2012 5:14:39 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
מאי 01, 2012 5:14:39 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null

这些消息是什么意思?

hibernate.cfg.xml:

<session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">org.h2.Driver</property>
    <property name="connection.url">jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE</property>
    <property name="connection.username">user</property>
    <property name="connection.password">password</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.H2Dialect</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">create</property>

    <!-- Names the annotated entity class -->
    <mapping class="database.datatypes.Course"/>
    <mapping class="database.datatypes.Distance"/>
    <mapping class="database.datatypes.ExamRange"/>
    <mapping class="database.datatypes.NumExamsOnDate"/>
    <mapping class="database.datatypes.RecommendedSchedule"/>

</session-factory>

代表表的类之一:

@Entity public class Distance {

private Course courseA, courseB;
private Long MinDistance, Cost;

@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment")
private Long id;


public Distance() {
    super();
}

public Distance(Course courseA, Course courseB, Long minDistance, Long cost) {
    super();
    this.courseA = courseA;
    this.courseB = courseB;
    MinDistance = minDistance;
    Cost = cost;
}


@Override
public String toString() {
    return "Distance [courseA=" + courseA + ", courseB=" + courseB
            + ", MinDistance=" + MinDistance + ", Cost=" + Cost + "]";
}

public Course getCourseA() {
    return courseA;
}

public void setCourseA(Course courseA) {
    this.courseA = courseA;
}

public Course getCourseB() {
    return courseB;
}

public void setCourseB(Course courseB) {
    this.courseB = courseB;
}

public Long getMinDistance() {
    return MinDistance;
}

public void setMinDistance(Long minDistance) {
    MinDistance = minDistance;
}

public Long getCost() {
    return Cost;
}

public void setCost(Long cost) {
    Cost = cost;
}

public Long getId() {
    return id;
}

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

}

谢谢。

【问题讨论】:

  • 是Hibernate的正常日志输出,没有任何问题。究竟是什么问题?

标签: hibernate configuration h2


【解决方案1】:

如您所见,您提到的消息来自 INFO 级别。来自这个日志级别的消息通常会让你知道底层框架(这里是 Hibernate)在做什么。所以,在那种情况下,一切都很好。如果您认为这些消息太令人不安,只需将日志级别更改为类似 WARN。

【讨论】:

  • 除非我记错了,DEBUGINFO 更健谈...如果你想要更少的消息,你应该使用WARN(只记录警告和错误)。跨度>
  • 糟糕,我错了!你是绝对正确的。无论如何,重点是@Yonatan K 可以简单地更改日志级别以减少日志文件中的详细程度。
  • 你是对的,关键是改变日志级别。我想如果你更新你的答案是有道理的(我不想自己这样做,因为这是你的答案)。
猜你喜欢
  • 1970-01-01
  • 2013-02-07
  • 2011-12-31
  • 2017-06-14
  • 1970-01-01
  • 1970-01-01
  • 2020-02-12
  • 1970-01-01
  • 2013-09-14
相关资源
最近更新 更多