Five words - How do I map this?
OK...so maybe some more words are in order. I have a CommunicationVo that has as a property another Vo...mapped to a different table, it's legacy data, so, of course, it has a composite key. A little mapping help here?
version - Hibernate 2.1.2
mapping documents ->
UserClosedQuestionVo.hbm.xml -
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ClosedQuestionVo" table="ClosedEndedQuestions">
<composite-id>
<key-property name="userID" column="UserID"/>
<key-property name="matchID" column="MatchID"/>
</composite-id>
<property name="closedQuestionID1" column="ClosedEndedQuestionID1"/>
<property name="closedQuestionID2" column="ClosedEndedQuestionID2"/>
<property name="closedQuestionID3" column="ClosedEndedQuestionID3"/>
<property name="closedQuestionID4" column="ClosedEndedQuestionID4"/>
<property name="closedQuestionID5" column="ClosedEndedQuestionID5"/>
</class>
</hibernate-mapping>
This does not work -
CommunicationVo.hbm.xml -
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.eharmony.ehweb.value.CommunicationVo" table="ehCommunication">
<id name="id" type="int" unsaved-value="0" column="CommunicationID">
<generator class="native"/>
</id>
<property name="lastRecieved" column="CommLastSent"/>
<property name="lastSent" column="CommLastRecieved"/>
<one-to-one name="questions" class="com.eharmony.ehweb.value.UserClosedQuestionVo"/>
<property name="started"/>
</class>
</hibernate-mapping>
The Java Code -
UserClosedQuestionVo.java
public class UserClosedQuestionVo
extends UserQuestionVo {
private int closedQuestionID1;
private int closedQuestionID2;
private int closedQuestionID3;
private int closedQuestionID4;
private int closedQuestionID5;
public void setClosedQuestionID1(int i) {
closedQuestionID1 = i;
}
public int getClosedQuestionID1() {
return closedQuestionID1;
}
public void setClosedQuestionID2(int i) {
closedQuestionID2 = i;
}
public int getClosedQuestionID2() {
return closedQuestionID2;
}
public void setClosedQuestionID3(int i) {
closedQuestionID3 = i;
}
public int getClosedQuestionID3() {
return closedQuestionID3;
}
public void setClosedQuestionID4(int i) {
closedQuestionID4 = i;
}
public int getClosedQuestionID4() {
return closedQuestionID4;
}
public void setClosedQuestionID5(int i) {
closedQuestionID5 = i;
}
public int getClosedQuestionID5() {
return closedQuestionID5;
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!super.equals(o)) {
return false;
}
if (o == null) {
return false;
}
if (o.getClass() != getClass()) {
return false;
}
UserClosedQuestionVo castedObj = (UserClosedQuestionVo) o;
return ((this.closedQuestionID1 == castedObj.closedQuestionID1) &&
(this.closedQuestionID2 == castedObj.closedQuestionID2) &&
(this.closedQuestionID3 == castedObj.closedQuestionID3) &&
(this.closedQuestionID4 == castedObj.closedQuestionID4) &&
(this.closedQuestionID5 == castedObj.closedQuestionID5));
}
public int hashCode() {
int hashCode = super.hashCode();
hashCode = (31 * hashCode) + closedQuestionID1;
hashCode = (31 * hashCode) + closedQuestionID2;
hashCode = (31 * hashCode) + closedQuestionID3;
hashCode = (31 * hashCode) + closedQuestionID4;
hashCode = (31 * hashCode) + closedQuestionID5;
return hashCode;
}
}
UserQuestionVo.java
public abstract class UserQuestionVo
implements Serializable {
protected Date questionTimestamp;
protected int matchID;
protected int userID;
public void setMatchID(int i) {
matchID = i;
}
public int getMatchID() {
return matchID;
}
public void setQuestionTimestamp(Date date) {
questionTimestamp = date;
}
public Date getQuestionTimestamp() {
return questionTimestamp;
}
public void setUserID(int i) {
userID = i;
}
public int getUserID() {
return userID;
}
}
Here's the stack trace
[INFO] Configuration - -Mapping file: /home/rmarkle/workspace/ehweb_web/src/java/com/eharmony/ehweb/value/CommunicationVo.hbm.xml
[DEBUG] DTDEntityResolver - -trying to locate
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
[DEBUG] DTDEntityResolver - -found
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
[INFO] Binder - -Mapping class: com.eharmony.ehweb.value.CommunicationVo -> ehCommunication
[DEBUG] Binder - -Mapped property: id -> CommunicationID, type: integer
[DEBUG] Binder - -Mapped property: lastRecieved -> CommLastSent, type: timestamp
[DEBUG] Binder - -Mapped property: lastSent -> CommLastRecieved, type: timestamp
[DEBUG] Binder - -Mapped property: questions, type: com.eharmony.ehweb.value.UserClosedQuestionVo
[DEBUG] Binder - -Mapped property: started -> CommStarted, type: timestamp
[INFO] Configuration - -processing one-to-many association mappings
[INFO] Configuration - -processing one-to-one association property references
[INFO] Configuration - -processing foreign key constraints
[INFO] Dialect - -Using dialect: net.sf.hibernate.dialect.SQLServerDialect
[INFO] SettingsFactory - -Maximim outer join fetch depth: 1
[INFO] SettingsFactory - -Use outer join fetching: true
[INFO] DriverManagerConnectionProvider - -Using Hibernate built-in connection pool (not for production use!)
[INFO] DriverManagerConnectionProvider - -Hibernate connection pool size: 1
[INFO] DriverManagerConnectionProvider - -using driver: com.inet.tds.TdsDriver at URL: jdbc:inetdae7:ehdb?database=eharmony_verona
[INFO] DriverManagerConnectionProvider - -connection properties: {user=eharmony, password=eh264zf4f}
[INFO] TransactionManagerLookupFactory - -No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
[DEBUG] DriverManagerConnectionProvider - -opening new JDBC connection
[DEBUG] DriverManagerConnectionProvider - -created connection to: jdbc:inetdae7:ehdb?database=eharmony_verona, Isolation Level: 2
[INFO] SettingsFactory - -Use scrollable result sets: true
[INFO] SettingsFactory - -Query language substitutions: {no='N', true=1, yes='Y', false=0}
[INFO] SettingsFactory - -cache provider: net.sf.hibernate.cache.HashtableCacheProvider
[INFO] Configuration - -instantiating and configuring caches
[INFO] SessionFactoryImpl - -building session factory
[DEBUG] SessionFactoryImpl - -instantiating session factory with properties: {hibernate.connection.driver_class=com.inet.tds.TdsDriver, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=eharmony, hibernate.connection.url=jdbc:inetdae7:ehdb?database=eharmony_verona, hibernate.connection.password=eh264zf4f, hibernate.connection.pool_size=1}
net.sf.hibernate.MappingException: No persister for: com.eharmony.ehweb.value.UserClosedQuestionVo
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:437)
at net.sf.hibernate.persister.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:106)
at net.sf.hibernate.persister.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:80)
at net.sf.hibernate.persister.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:518)
at net.sf.hibernate.persister.EntityPersister.postInstantiate(EntityPersister.java:111)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:156)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:739)
at net.sf.hibern8ide.Hibern8IDE.initialize(Hibern8IDE.java:171)
at net.sf.hibern8ide.Hibern8IDE.reconfig(Hibern8IDE.java:160)
at net.sf.hibern8ide.Hibern8IDE$6.configurationChanged(Hibern8IDE.java:586)
at net.sf.hibern8ide.ConfigurationUI$ApplyConfig.actionPerformed(ConfigurationUI.java:245)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)