Исключение, хотя отношение многие-к-одному org.hibernate.MappingException: не удалось определить тип для - PullRequest
1 голос
/ 05 мая 2011

Я хочу написать простую многомерную ORM, используя Hibernate.У меня есть буксирные столы, пользователь и местоположение.Местоположение содержит названия стран, одно из которых я хочу указать в пользовательском классе.

public class User extends  BusinessBaseImpl implements UserInterface{

private String id;
private String firstName;
private String lastName;
private String mobileNumber;
private Location location;
private String email;
private String password;
private String type;

public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
    makeDirty();
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
    makeDirty();
}
public String getMobileNumber() {
    return mobileNumber;
}
public void setMobileNumber(String mobileNumber) {
    this.mobileNumber = mobileNumber;
    makeDirty();
}
public Location getLocation() {
    return location;
}
public void setLocation(Location location) {
    this.location = location;
    makeDirty();
}
public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
    makeDirty();
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
    makeDirty();
}
public String getType() {
    return type;
}
public void setType(String type) {
    this.type = type;
    makeDirty();
}
public String getId() {
    return id;
}
@SuppressWarnings("unused")
private void setId(String id){
    this.id = id;
}
/**
 *
 * Private constructor.
 */
public User(){
    this.id = CoreService.getUID();
    this.isNew = true;
    this.isDirty = false;
}

}

файл конфигурации Hibernate

<hibernate-mapping>
<class name="pspl.assignment.businessimpl.User" table="user">
    <id name="id" type="string" column="id">
        <generator class="assigned"></generator>
    </id>

    <property name="firstName">
        <column name="firstname" />
    </property>
    <property name="lastName">
        <column name="lastname" />
    </property>
    <property name="email">
        <column name="email" />
    </property>
    <property name="mobileNumber">
        <column name="mobilenumber" />
    </property>
    <many-to-one name="location" class="pspl.assignment.businessimpl.Location" column="location"  >
    </many-to-one>  
    <property name="password">
        <column name="password" />
    </property>
    <property name="type">
        <column name="type" />
    </property>
</class>

класс местоположения

public class Location extends BusinessBaseImpl {

private String id;
private String contryName;

public String getId() {
    return id;
}

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

public String getContryName() {
    return contryName;
}

public void setContryName(String contryName) {
    this.contryName = contryName;
}

public Location(){
    this.setId(CoreService.getUID());
    this.isDirty = false;
    this.isNew = true;
}

public static Location createNew(){
    return new Location();
}

}

При выполнении теста для пользовательского класса я получаю следующее исключение

org.hibernate.MappingException: Could not determine type for: pspl.assignment.businessimpl.Location, at table: user, for columns: [org.hibernate.mapping.Column(location)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:269)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)..............

Файл сопоставления для locaion

<hibernate-mapping>
<class name="pspl.assignment.businessimpl.Location" table="location">
    <id name="id" type="string" column="id"></id>
    <property name="contryName"><column name="contryname"/> </property>
</class> 

Файл конфигурации Hibernate

<hibernate-configuration>

  <mapping resource="location.hbm.xml"/>
  <mapping resource="user.hbm.xml"/>

Я новичок в Hibernate, и я не знаю, гдея делаю ошибку.

спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...