【问题标题】:Hibernate ORM Failed:org.hibernate.MappingException: Could not determine type for:Hibernate ORM 失败:org.hibernate.MappingException:无法确定类型:
【发布时间】:2016-08-16 18:38:53
【问题描述】:

我在休眠配置 xml 中遇到问题。

实体:

package com.ds.supercar.model.places;

公开课位置{

private int locationid;
private String street;
private String city;
private String state;
private String pin;

public Location() {
    // TODO Auto-generated constructor stub
}

public Location(int locationid, String street, String city, String state, String pin) {
    super();
    this.locationid = locationid;
    this.street = street;
    this.city = city;
    this.state = state;
    this.pin = pin;
}

public int getLocationid() {
    return locationid;
}

public void setLocationid(int locationid) {
    this.locationid = locationid;
}

public String getStreet() {
    return street;
}

public void setStreet(String street) {
    this.street = street;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getState() {
    return state;
}

public void setState(String state) {
    this.state = state;
}

public String getPin() {
    return pin;
}

public void setPin(String pin) {
    this.pin = pin;
}

}

hbm xml 文件:

<hibernate-mapping>
<class name="com.ds.supercar.model.places.Location" table="supercarlocation" schema="supercar">
    <id name="locationid" column="locationid">
        <generator class="increment"/>
    </id>
    <property name="street"/>
    <property name="city"/>
    <property name="state"/>
    <property name="pin"/>
    </class>

例外:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).

log4j:WARN 请正确初始化log4j系统。 初始 SessionFactory 创建失败:org.hibernate.MappingException:无法确定类型:com.ds.supercar.model.places.Location,列:[org.hibernate.mapping.Column(branchlocation)] 线程“主”java.lang.ExceptionInInitializerError 中的异常 在 Test.main(Test.java:19) 引起:org.hibernate.MappingException:无法确定类型:com.ds.supercar.model.places.Location,列:[org.hibernate.mapping.Column(branchlocation)] 在 org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:244) 在 org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:231) 在 org.hibernate.mapping.Property.isValid(Property.java:174) 在 org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:308) 在 org.hibernate.mapping.RootClass.validate(RootClass.java:186) 在 org.hibernate.cfg.Configuration.validate(Configuration.java:816) 在 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1050) 在 Test.main(Test.java:13)

请帮我解决这个例外:

【问题讨论】:

  • 这是您唯一拥有的表和实体吗?

标签: java hibernate orm


【解决方案1】:

您似乎忘记将映射资源放在您的休眠配置文件中(在 sessionFactory 标签之间) 所以使用它并映射你的 hbm。

&lt;mapping resource="com.ds.supercar.model.places.Location.hbm.xml" /&gt;

希望对你有帮助!

【讨论】:

  • MR1: 我已经在配置文件中添加了映射资源
  • 也许您应该检查您的 Hibernate 类或检查您的 jdbc 驱动程序等。要解决所有这些问题,您可以按照本教程进行操作:tutorialspoint.com/hibernate/hibernate_examples.htm 快速猜测是使用 default-lazy="false " 和休眠映射标签中的 auto-import="true" 。
猜你喜欢
  • 2014-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-18
  • 2013-01-25
  • 1970-01-01
相关资源
最近更新 更多