2016-04-23 55 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」。 –

相關問題