我需要在Hibernate中使用一些遗留类。其中一个类没有默认构造函数,所以我得到一个“org.hibernate.InstantiationException:没有实体的默认构造函数:..”错误。我不需要直接坚持这个课。这里是映射:Hibernate可以使用没有默认c'tor的类作为组件或复合元素吗?
<class name="test.geo.support.Observation" table="observation">
<id access="property" column="obs_msg" name="EncodedObMsg" type="string"/>
<property name="ReportTime" column="report_time" type="long" />
<many-to-one name="Station" column="station_id" class="test.geo.Station"/>
</class>
<class name="test.geo.Station" table="station">
<id access="property" column="station_id" name="UniqueId" type="string" />
<component name="Point" class="test.geo.geometry.PointGeometry">
<property name="latitude" type="double" access="field" column="lat" />
<property name="longitude" type="double" access="field" column="lon" />
</component>
</class>
我需要坚持的“观察”和“站”,并要参考“PointGeometry”类持久化Station.Point。有没有什么办法可以用'PointGeometry'来取消默认构造函数?
无参数的构造函数,最多可以包专用 – hvgotcodes 2011-06-09 14:35:38
@hvgotcodes'protected' definitelly工作,因为它是所有在我的代码。但我回过头来谈谈“私人”。回答编辑。 – 2011-06-09 16:02:14
是受保护的将会起作用,因为它比私人包的限制性更小。注意“包私人”是一个术语。我没有说私人。 – hvgotcodes 2011-06-09 16:32:18