2016-04-23 25 views
1

我在hibernate config xml中遇到问题。Hibernate ORM失败:org.hibernate.MappingException:无法确定类型:

实体:

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的系统。 初始会话创建失败:org.hibernate.MappingException:无法确定类型:com.ds.supercar.model.places.Location,列:[org.hibernate.mapping.Column(branchlocation)] 线程中的异常“ main“java.lang.ExceptionInInitializerError at 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.PersistentClass.validate(PersistentClass.java:308)0123(org.hibernate.mapping.Property.isValid(Property.java:174) ) org.hibernate.mapping.RootClass.validate(RootClass.java:186) at org.hibernate.cfg.Configuration.validate(Configuration.java:816) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration。 Java的:1050) 在Test.main(Test.java:13)

请帮我与此异常:

+0

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

回答

0

看来你忘了把资源映射在Hibernate配置文件(SessionFactory的标签之间) 所以使用这个和映射你的hbm's。

<mapping resource="com.ds.supercar.model.places.Location.hbm.xml" />

希望这可以帮助你!

+0

MR1:我已经在配置文件 Naveen

+0

也许你应该检查你的Hibernate类或检查你的jdbc驱动程序等。要解决所有这些,你可以按照这个教程:http://www.tutorialspoint。 com/hibernate/hibernate_examples.htm快速猜测是在hibernate-mapping标记中使用default-lazy =“false”和auto-import =“true”。 –

相关问题