Привет, у меня есть следующий код:
public class Trail {
private int trailID;
private Location startLocation;
private Location destination;
// Getters and setters
}
какое расположение является пользовательским типом БД, это не таблица
public class LocationType implements org.hibernate.usertype.CompositeUserType {
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if ( value == null ) {
DoubleType.INSTANCE.set(st, null, index, session);
DoubleType.INSTANCE.set(st, null, index+1, session);
DoubleType.INSTANCE.set(st, null, index+2, session);
StringType.INSTANCE.set(st, null, index+3, session);
} else {
final Location loc = (Location) value;
DoubleType.INSTANCE.set(st, loc.getLatitude(), index, session);
DoubleType.INSTANCE.set(st, loc.getLongitude(), index+1, session);
DoubleType.INSTANCE.set(st, loc.getAltitude(), index+2, session);
StringType.INSTANCE.set(st, loc.getDescription(), index+3, session);
}
}
// Other functions
}
и это мой класс Location
public class Location implements Serializable {
...
}
Trail.hbm.xml выглядит так:
<hibernate-mapping package="com.mytest.walking">
<class name="Trail" table="TB_Trail" dynamic-insert="true">
<id name="TrailID" column="TrailID" >
<generator class="native"/>
</id>
<property name="StartLocation" type="LocationType" >
<column name="latitude" />
<column name="longitude" />
<column name="altitude" />
<column name="description" />
</property>
<property name="Destination" type="LocationType" >
<column name="latitude" />
<column name="longitude" />
<column name="altitude" />
<column name="description" />
</property>
</class>
</hibernate-mapping>
Тогда я получил следующее исключение
Caused by: org.hibernate.MappingException: property mapping has wrong number of columns: com.mytest.walking.Trail.Destination type: com.mytest.walking.LocationType
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:468)
at org.hibernate.mapping.RootClass.validate(RootClass.java:268)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1287)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1729)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:184)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:314)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
Может ли кто-нибудь указать мне правильное направление, как избавиться от этого исключения?